Prompt specification
Build or customize the Three.js 3D scene "Fountain supply teaching model" 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: Fountain supply teaching model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fountain-supply-teaching-model-x1515
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing pressure and energy in a Venturi tube. Compose a reservoir, pipe, nozzle, and water jet with energy labels; show ideal conversion while clearly identifying friction and jet breakup as omitted effects. Voxel style.
Working Three.js Starter (fountain-supply-teaching-model-x1515):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Venturi — Pressure and Energy</title>
<style>
:root {
--bg: #07141f;
--panel: rgba(8, 24, 37, 0.88);
--line: rgba(157, 210, 232, 0.22);
--text: #edf8ff;
--muted: #9db4c2;
--blue: #38a9ff;
--cyan: #65e5ff;
--amber: #ffc45c;
--green: #70e1a1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#app canvas {
cursor: grab;
touch-action: none;
}
#app canvas.dragging {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.topbar {
position: absolute;
top: 20px;
left: 22px;
max-width: 620px;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 3px;
background: var(--cyan);
box-shadow: 0 0 14px rgba(101, 229, 255, 0.7);
}
h1 {
margin: 7px 0 3px;
font-size: clamp(25px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 0;
color: #b9d0dc;
font-size: 13px;
letter-spacing: 0.03em;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 13px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(4, 17, 27, 0.65);
color: #c6d9e4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--color);
box-shadow: 0 0 9px var(--color);
}
.energy-panel {
position: absolute;
top: 20px;
right: 20px;
width: 326px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 12px;
background:
linear-gradient(145deg, rgba(18, 44, 61, 0.92), rgba(5, 18, 29, 0.92));
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(14px);
}
.panel-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
margin-bottom: 12px;
}
.panel-heading strong {
font-size: 12px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.ideal-pill {
padding: 4px 7px;
border: 1px solid rgba(255, 196, 92, 0.36);
border-radius: 999px;
color: var(--amber);
background: rgba(255, 196, 92, 0.08);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
}
.equation {
padding: 11px 12px;
border: 1px solid rgba(101, 229, 255, 0.2);
border-radius: 7px;
background: rgba(0, 10, 18, 0.42);
color: #dff7ff;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 13px;
text-align: center;
}
.equation .total {
margin-top: 7px;
color: var(--cyan);
font-size: 11px;
}
.budget {
margin-top: 15px;
}
.budget-title {
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.budget-row {
margin: 11px 0;
}
.budget-row .row-head {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 5px;
font-size: 11px;
}
.budget-row .row-head span:last-child {
color: #b9cfdb;
font-family: "SFMono-Regular", Consolas, monospace;
}
.bar {
display: flex;
height: 8px;
overflow: hidden;
border-radius: 3px;
background: rgba(255, 255, 255, 0.07);
}
.bar .pressure {
width: 95.2%;
background: var(--blue);
box-shadow: 0 0 12px rgba(56, 169, 255, 0.5);
}
.bar .kinetic {
width: 4.8%;
background: var(--amber);
}
.bar .all-kinetic {
width: 100%;
background: linear-gradient(90deg, #ffb13d, #ffe08b);
box-shadow: 0 0 12px rgba(255, 196, 92, 0.45);
}
.balance {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 9px;
margin-top: 13px;
padding: 10px;
border: 1px solid rgba(112, 225, 161, 0.2);
border-radius: 7px;
background: rgba(112, 225, 161, 0.055);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
text-align: center;
}
.balance .left {
color: #9ed4ff;
}
.balance .right {
color: #ffda91;
}
.balance .equal {
color: var(--green);
font-weight: 900;
}
.model-note {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.model-note strong {
color: var(--amber);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label {
position: absolute;
top: 0;
left: 0;
width: max-content;
max-width: 235px;
pointer-events: none;
filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45));
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -19px;
width: 1px;
height: 18px;
background: linear-gradient(var(--accent), transparent);
opacity: 0.85;
}
.world-label::before {
content: "";
position: absolute;
left: calc(50% - 3px);
bottom: -22px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 9px var(--accent);
}
.tag-card {
padding: 9px 11px;
border: 1px solid color-mix(in srgb, var(--accent) 52%, transparent);
border-left: 4px solid var(--accent);
border-radius: 6px;
background: rgba(5, 19, 30, 0.9);
backdrop-filter: blur(8px);
}
.tag-title {
display: flex;
align-items: center;
gap: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.tag-value {
margin-top: 4px;
color: #f3fbff;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
font-weight: 750;
}
.tag-sub {
margin-top: 3px;
color: #9fb8c7;
font-size: 10px;
line-height: 1.35;
}
.controls {
position: absolute;
left: 22px;
bottom: 72px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.controls button {
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 6px;
color: #d9edf7;
background: rgba(7, 24, 37, 0.82);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.controls button:hover {
border-color: rgba(101, 229, 255, 0.6);
background: rgba(15, 47, 66, 0.9);
transform: translateY(-1px);
}
.control-hint {
margin-left: 3px;
color: #829baa;
font-size: 10px;
letter-spacing: 0.04em;
}
.omission-banner {
position: absolute;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
width: max-content;
max-width: calc(100% - 32px);
padding: 9px 14px;
border: 1px solid rgba(255, 196, 92, 0.32);
border-radius: 7px;
color: #c9d7df;
background: rgba(8, 22, 31, 0.9);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
font-size: 10px;
line-height: 1.4;
backdrop-filter: blur(10px);
}
.omission-banner strong {
color: var(--amber);
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.omission-banner .divider {
width: 1px;
height: 14px;
background: rgba(255, 255, 255, 0.18);
}
@media (max-width: 980px) {
.energy-panel {
width: 286px;
padding: 14px;
}
.world-label {
max-width: 205px;
}
.tag-sub {
display: none;
}
.control-hint {
display: none;
}
}
@media (max-width: 680px) {
.topbar {
top: 13px;
left: 14px;
}
h1 {
font-size: 25px;
}
.subtitle {
max-width: 330px;
font-size: 10px;
}
.legend {
display: none;
}
.energy-panel {
display: none;
}
.controls {
left: 14px;
bottom: 70px;
}
.world-label {
max-width: 168px;
}
.tag-card {
padding: 7px 8px;
}
.tag-value {
font-size: 10px;
}
.omission-banner {
bottom: 10px;
flex-wrap: wrap;
gap: 5px 9px;
justify-content: flex-start;
padding: 8px 10px;
}
.omission-banner .divider {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="hud">
<header class="topbar">
<div class="eyebrow">Voxel Fluid Lab / 01</div>
<h1>Venturi Energy Conversion</h1>
<p class="subtitle">
Reservoir → contraction → nozzle → coherent water jet
</p>
<div class="legend" aria-label="Energy legend">
<span><i style="--color:#38a9ff"></i>Pressure energy</span>
<span><i style="--color:#70e1a1"></i>Potential energy</span>
<span><i style="--color:#ffc45c"></i>Kinetic energy</span>
</div>
</header>
<aside class="energy-panel" aria-label="Ideal energy ledger">
<div class="panel-heading">
<strong>Ideal Energy Ledger</strong>
<span class="ideal-pill">LOSS-FREE</span>
</div>
<div class="equation">
z + p/ρg + v²/2g = constant
<div class="total">Total head = 2.400 m</div>
</div>
<div class="budget">
<div class="budget-title">Section 1 · upstream pipe</div>
<div class="budget-row">
<div class="row-head">
<span>Pressure head</span>
<span>2.285 m</span>
</div>
<div class="bar">
<div class="pressure"></div>
<div class="kinetic"></div>
</div>
</div>
<div class="budget-row">
<div class="row-head">
<span>Velocity head</span>
<span>0.115 m</span>
</div>
<div class="bar">
<div class="pressure" style="width:4.8%"></div>
<div class="kinetic" style="width:95.2%"></div>
</div>
</div>
<div class="budget-title" style="margin-top:16px">
Section 2 · nozzle exit
</div>
<div class="budget-row">
<div class="row-head">
<span>Pressure head</span>
<span>0.000 m</span>
</div>
<div class="bar"></div>
</div>
<div class="budget-row">
<div class="row-head">
<span>Velocity head</span>
<span>2.400 m</span>
</div>
<div class="bar">
<div class="all-kinetic"></div>
</div>
</div>
<div class="balance">
<span class="left">2.285 + 0.115</span>
<span class="equal">=</span>
<span class="right">0 + 2.400</span>
</div>
</div>
<div class="model-note">
<strong>Idealized assumptions</strong><br>
Gauge pressure · ρ = 1000 kg/m³ · g = 9.81 m/s²<br>
Datum is the nozzle axis. Sections 1 and 2 share elevation.
</div>
</aside>
<div class="controls">
<button id="pauseButton" type="button">Pause flow</button>
<button id="resetButton" type="button">Reset view</button>
<span class="control-hint">Drag to orbit · Scroll to zoom</span>
</div>
<div class="omission-banner">
<strong>Omitted effects:</strong>
<span>wall friction / viscosity</span>
<span class="divider"></span>
<span>turbulence</span>
<span class="divider"></span>
<span>jet breakup</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Physical model: ideal Bernoulli flow from an open reservoir to a nozzle.
// -------------------------------------------------------------------------
const rho = 1000;
const g = 9.81;
const totalHead = 2.400; // reservoir surface above nozzle-axis datum
const v1 = 1.500; // upstream pipe velocity
const velocityHead1 = v1 * v1 / (2 * g);
const pressureHead1 = totalHead - velocityHead1;
const pressure1 = rho * g * pressureHead1;
const v2 = Math.sqrt(2 * g * totalHead);
const area1 = 0.050;
const flowRate = area1 * v1;
const area2 = flowRate / v2;
const diameterRatio = Math.sqrt(area2 / area1);
// -------------------------------------------------------------------------
// Renderer and scene.
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07141f);
scene.fog = new THREE.Fog(0x07141f, 18, 34);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.15;
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.35, 1.0, 0);
const orbit = {
theta: -0.72,
phi: 0.93,
zoom: 1
};
function updateCamera() {
const radius = 14;
const horizontal = Math.sin(orbit.phi) * radius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(orbit.theta),
cameraTarget.y + Math.cos(orbit.phi) * radius,
cameraTarget.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(8.8, 13.4 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Lighting and materials.
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc9efff, 0x172331, 2.15));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x27baff, 14, 8, 2);
cyanLight.position.set(-1.4, 2.4, 2.0);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa83b, 13, 7, 2);
amberLight.position.set(4.0, 1.8, 1.8);
scene.add(amberLight);
const unitCube = new THREE.BoxGeometry(1, 1, 1);
const materials = {
tile: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
metalness: 0.02
}),
tank: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0.08
}),
pipe: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.58,
metalness: 0.16
}),
nozzle: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.4,
metalness: 0.32
}),
water: new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0x063b72,
emissiveIntensity: 0.58,
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.78,
depthWrite: true
}),
jet: new THREE.MeshStandardMaterial({
color: 0x38a9ff,
emissive: 0x075ca5,
emissiveIntensity: 0.72,
roughness: 0.25,
transparent: true,
opacity: 0.86
}),
green: new THREE.MeshStandardMaterial({
color: 0x70e1a1,
emissive: 0x1d8f57,
emissiveIntensity: 0.75,
roughness: 0.42
}),
arrow: new THREE.MeshStandardMaterial({
color: 0xffc45c,
emissive: 0xa95c08,
emissiveIntensity: 0.8,
roughness: 0.4
})
};
const dummy = new THREE.Object3D();
const color = new THREE.Color();
function createInstances(items, material, options = {}) {
const mesh = new THREE.InstancedMesh(unitCube, material, items.length);
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (item.color !== undefined) {
color.set(item.color);
mesh.setColorAt(index, color);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
scene.add(mesh);
return mesh;
}
function randomVariation(base, amount = 0.08) {
color.set(base);
color.offsetHSL(0, 0, (Math.random() - 0.5) * amount);
return `#${color.getHexString()}`;
}
// -------------------------------------------------------------------------
// Voxel ground platform.
// -------------------------------------------------------------------------
const groundItems = [];
for (let x = -8; x <= 8; x++) {
for (let z = -3; z <= 3; z++) {
groundItems.push({
x,
y: -0.96 + Math.random() * 0.015,
z,
sx: 0.94,
sy: 0.12,
sz: 0.94,
color: randomVariation("#173044", 0.12)
});
}
}
createInstances(groundItems, materials.tile, {
castShadow: false,
receiveShadow: true
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(17.4, 0.42, 7.4),
new THREE.MeshStandardMaterial({
color: 0x0a1c2a,
roughness: 0.95
})
);
base.position.set(0, -1.24, 0);
base.receiveShadow = true;
scene.add(base);
// -------------------------------------------------------------------------
// Open, cutaway voxel reservoir.
// -------------------------------------------------------------------------
const tankItems = [];
const waterItems = [];
const tankStep = 0.36;
const tankXs = [];
const tankYs = [];
const tankZs = [];
for (let x = -5.18; x <= -3.02; x += tankStep) tankXs.push(x);
for (let y = -0.55; y <= 3.23; y += tankStep) tankYs.push(y);
for (let z = -0.92; z <= 0.92; z += tankStep) tankZs.push(z);
// Rear wall.
for (const x of tankXs) {
for (const y of tankYs) {
tankItems.push({
x,
y,
z: -1.08,
sx: 0.35,
sy: 0.35,
sz: 0.35,
color: randomVariation("#5c7480", 0.13)
});
}
}
// Side walls.
for (const x of [-5.23, -2.97]) {
for (const y of tankYs) {
for (const z of tankZs) {
tankItems.push({
x,
y,
z,
sx: 0.35,
sy: 0.35,
sz: 0.35,
color: randomVariation("#536c79", 0.14)
});
}
}
}
// Bottom.
for (const x of tankXs) {
for (const z of tankZs) {
tankItems.push({
x,
y: -0.56,
z,
sx: 0.35,
sy: 0.35,
sz: 0.35,
color: randomVariation("#405966", 0.12)
});
}
}
// Top rear and side rim.
for (const x of tankXs) {
tankItems.push({
x,
y: 3.23,
z: -1.08,
sx: 0.35,
sy: 0.35,
sz: 0.35,
color: "#78909a"
});
}
// Water volume as visible cubic cells.
const waterXs = [-4.98, -4.62, -4.26, -3.90, -3.54, -3.18];
const waterYs = [-0.37, -0.01, 0.35, 0.71, 1.07, 1.43, 1.79, 2.15, 2.51, 2.87];
const waterZs = [-0.72, -0.36, 0, 0.36, 0.72];
for (const x of waterXs) {
for (const y of waterYs) {
for (const z of waterZs) {
const isSurface = y > 2.7;
waterItems.push({
x,
y,
z,
sx: 0.335,
sy: 0.335,
sz: 0.335,
color: isSurface
? randomVariation("#46bfff", 0.1)
: randomVariation("#087ed3", 0.12)
});
}
}
}
createInstances(tankItems, materials.tank);
createInstances(waterItems, materials.water, {
castShadow: false,
receiveShadow: true
});
// Green voxel elevation ruler: free surface to nozzle-axis datum.
const elevationItems = [];
for (let y = 0.75; y <= 2.75; y += 0.4) {
elevationItems.push({
x: -5.55,
y,
z: 0.74,
sx: 0.09,
sy: 0.28,
sz: 0.09,
color: "#70e1a1"
});
}
elevationItems.push(
{
x: -5.55,
y: 2.92,
z: 0.74,
sx: 0.09,
sy: 0.18,
sz: 0.09,
color: "#70e1a1"
},
{
x: -5.48,
y: 3.03,
z: 0.74,
sx: 0.23,
sy: 0.09,
sz: 0.09,
color: "#70e1a1"
}
);
createInstances(elevationItems, materials.green, {
castShadow: false
});
// -------------------------------------------------------------------------
// Voxel pipe with a front cutaway and converging nozzle.
// -------------------------------------------------------------------------
const axisY = 0.55;
const pipeItems = [];
const nozzleItems = [];
const coreItems = [];
const pipeStep = 0.28;
const pipeStart = -2.94;
const pipeEnd = 2.25;
function smoothstep(t) {
return t * t * (3 - 2 * t);
}
function pipeRadius(x) {
if (x < -0.25) return 0.58;
if (x < 1.08) {
const t = smoothstep((x + 0.25) / 1.33);
return THREE.MathUtils.lerp(0.58, 0.22, t);
}
return 0.22;
}
for (let x = pipeStart; x <= pipeEnd; x += pipeStep) {
const radius = pipeRadius(x);
const isNozzle = x >= 1.08;
const shellSize = isNozzle ? 0.18 : 0.28;
for (let a = 0; a < 8; a++) {
const angle = a * Math.PI / 4;
const z = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
// Remove the front-facing half of the broad pipe for a cutaway view.
const frontCutaway = !isNozzle && z > 0.12;
if (frontCutaway) continue;
const item = {
x,
y: axisY + y,
z,
sx: shellSize,
sy: shellSize,
sz: shellSize,
color: randomVariation(isNozzle ? "#415e70" : "#c0d2d8", 0.1)
};
if (isNozzle) nozzleItems.push(item);
else pipeItems.push(item);
}
// Cubic water core.
let offsets = [0];
let cellSize = 0.17;
if (radius > 0.45) {
offsets = [-0.20, 0, 0.20];
cellSize = 0.195;
} else if (radius > 0.30) {
offsets = [-0.115, 0, 0.115];
cellSize = 0.125;
}
for (const oy of offsets) {
for (const oz of offsets) {
coreItems.push({
x,
y: axisY + oy,
z: oz,
sx: cellSize,
sy: cellSize,
sz: cellSize,
color: randomVariation("#1599ed", 0.08)
});
}
}
}
// Orange voxel exit flange.
for (let a = 0; a < 8; a++) {
const angle = a * Math.PI / 4;
nozzleItems.push({
x: 2.29,
y: axisY + Math.sin(angle) * 0.22,
z: Math.cos(angle) * 0.22,
sx: 0.21,
sy: 0.21,
sz: 0.21,
color: a % 2 ? "#ff9f36" : "#ffc45c"
});
}
createInstances(pipeItems, materials.pipe);
createInstances(nozzleItems, materials.nozzle);
createInstances(coreItems, materials.water, {
castShadow: false
});
// -------------------------------------------------------------------------
// Coherent voxel water jet. Breakup is intentionally omitted.
// -------------------------------------------------------------------------
const jetItems = [];
for (let x = 2.43; x <= 6.20; x += 0.25) {
jetItems.push({
x,
y: axisY,
z: 0,
sx: 0.245,
sy: 0.19,
sz: 0.19,
color: randomVariation("#36aaff", 0.09)
});
}
createInstances(jetItems, materials.jet, {
castShadow: false
});
// -------------------------------------------------------------------------
// Voxel flow arrows on the platform.
// -------------------------------------------------------------------------
const arrowItems = [];
function addVoxelArrow(x, z) {
arrowItems.push(
{ x: x - 0.18, y: -0.80, z, sx: 0.25, sy: 0.09, sz: 0.10, color: "#ffc45c" },
{ x: x + 0.04, y: -0.80, z, sx: 0.25, sy: 0.09, sz: 0.10, color: "#ffc45c" },
{ x: x + 0.26, y: -0.80, z, sx: 0.25, sy: 0.09, sz: 0.10, color: "#ffc45c" },
{ x: x + 0.40, y: -0.80, z: z + 0.10, sx: 0.14, sy: 0.09, sz: 0.14, color: "#ffd98a" },
{ x: x + 0.40, y: -0.80, z: z - 0.10, sx: 0.14, sy: 0.09, sz: 0.14, color: "#ffd98a" }
);
}
addVoxelArrow(-2.1, 1.48);
addVoxelArrow(0.1, 1.48);
addVoxelArrow(3.8, 1.48);
createInstances(arrowItems, materials.arrow, {
castShadow: false
});
// -------------------------------------------------------------------------
// Animated energy markers. Cyan upstream, amber where kinetic dominates.
// -------------------------------------------------------------------------
const markerCount = 34;
const markerGeometry = new THREE.BoxGeometry(0.11, 0.11, 0.11);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0x286a80,
emissiveIntensity: 1.3,
roughness: 0.25
});
const markerMesh = new THREE.InstancedMesh(
markerGeometry,
markerMaterial,
markerCount
);
markerMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
markerMesh.frustumCulled = false;
scene.add(markerMesh);
const markers = Array.from({ length: markerCount }, (_, index) => ({
s: index / markerCount,
laneY: (Math.random() - 0.5) * 0.35,
laneZ: (Math.random() - 0.5) * 0.35,
phase: Math.random() * Math.PI * 2
}));
function pathX(s) {
if (s < 0.48) {
return THREE.MathUtils.lerp(-2.78, 1.05, s / 0.48);
}
if (s < 0.55) {
return THREE.MathUtils.lerp(1.05, 2.30, (s - 0.48) / 0.07);
}
return THREE.MathUtils.lerp(2.30, 6.15, (s - 0.55) / 0.45);
}
const cyanMarker = new THREE.Color(0x8deaff);
const amberMarker = new THREE.Color(0xffca65);
function updateMarkers(time, dt, running) {
markers.forEach((marker, index) => {
if (running) {
marker.s += dt * 0.045;
if (marker.s >= 1) marker.s -= 1;
}
const x = pathX(marker.s);
const radius = pipeRadius(Math.min(x, 2.29));
const laneScale = Math.min(1, radius / 0.58);
const jetScale = x > 2.29 ? 0.18 : laneScale;
dummy.position.set(
x,
axisY + marker.laneY * jetScale,
marker.laneZ * jetScale
);
dummy.rotation.set(
time * 0.8 + marker.phase,
time * 1.1 + marker.phase,
0
);
dummy.scale.setScalar(0.9 + 0.12 * Math.sin(time * 4 + marker.phase));
dummy.updateMatrix();
markerMesh.setMatrixAt(index, dummy.matrix);
markerMesh.setColorAt(
index,
x > 1.15 ? amberMarker : cyanMarker
);
});
markerMesh.instanceMatrix.needsUpdate = true;
if (markerMesh.instanceColor) markerMesh.instanceColor.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Projected HTML labels, implemented without CSS2DRenderer or other addons.
// -------------------------------------------------------------------------
const labelsRoot = document.createElement("div");
labelsRoot.id = "labels";
labelsRoot.style.position = "fixed";
labelsRoot.style.inset = "0";
labelsRoot.style.pointerEvents = "none";
labelsRoot.style.zIndex = "4";
document.body.appendChild(labelsRoot);
function makeWorldLabel(accent, title, value, sub, anchor, offset = [0, 0]) {
const element = document.createElement("div");
element.className = "world-label";
element.style.setProperty("--accent", accent);
element.innerHTML = `
<div class="tag-card">
<div class="tag-title">${title}</div>
<div class="tag-value">${value}</div>
<div class="tag-sub">${sub}</div>
</div>
`;
labelsRoot.appendChild(element);
return {
element,
anchor: new THREE.Vector3(...anchor),
offset
};
}
const worldLabels = [
makeWorldLabel(
"#70e1a1",
"Reservoir · Potential",
"z = 2.400 m",
"Open surface: p = 0 kPa gauge · v ≈ 0",
[-4.15, 3.62, 0],
[-12, -4]
),
makeWorldLabel(
"#38a9ff",
"① Pressure Energy",
"p/ρg = 2.285 m",
`p = ${(pressure1 / 1000).toFixed(1)} kPa gauge · v₁ = ${v1.toFixed(2)} m/s`,
[-1.35, 1.82, 0.1],
[-5, -6]
),
makeWorldLabel(
"#b9d4df",
"Contraction",
`A₂/A₁ = ${(area2 / area1).toFixed(3)}`,
`d₂/d₁ ≈ ${diameterRatio.toFixed(2)} · Q = ${flowRate.toFixed(3)} m³/s`,
[0.62, 1.48, 0.05],
[0, -4]
),
makeWorldLabel(
"#ffc45c",
"② Kinetic Energy",
`v₂ = ${v2.toFixed(2)} m/s`,
"Atmospheric pressure at the exit",
[2.35, 1.55, 0.05],
[8, -8]
),
makeWorldLabel(
"#ffc45c",
"Ideal Coherent Jet",
"v²/2g = 2.400 m",
`Kinetic energy density = ${(rho * g * totalHead / 1000).toFixed(1)} kJ/m³`,
[4.65, 1.30, 0],
[8, -6]
)
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
worldLabels.forEach((label) => {
projected.copy(label.anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, calc(-100% - 18px))`;
});
}
// -------------------------------------------------------------------------
// Direct camera interaction: drag/orbit and wheel/zoom.
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.34, 1.34);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.75
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
function resetView() {
orbit.theta = -0.72;
orbit.phi = 0.93;
orbit.zoom = 1;
updateCamera();
}
const pauseButton = document.getElementById("pauseButton");
const resetButton = document.getElementById("resetButton");
let running = true;
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause flow" : "Resume flow";
});
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.theta += 0.08;
if (event.key === "ArrowRight") orbit.theta -= 0.08;
if (event.key === "ArrowUp") orbit.phi -= 0.06;
if (event.key === "ArrowDown") orbit.phi += 0.06;
if (event.key === "r" || event.key === "R") resetView();
updateCamera();
});
// -------------------------------------------------------------------------
// Animation.
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updateMarkers(elapsed, dt, running);
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```