Prompt specification
Build or customize the Three.js 3D scene "Venturi tube with pressure taps" 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: Venturi tube with pressure taps
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/venturi-tube-with-pressure-taps-x1513
Scene Description Prompt:
A low-poly Venturi tube shows lower throat pressure under ideal horizontal incompressible flow, using pressure taps. Three.js from cdnjs, one HTML file.
Working Three.js Starter (venturi-tube-with-pressure-taps-x1513):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Low-Poly Venturi Tube</title>
<style>
:root {
color-scheme: dark;
--cyan: #74ddff;
--cyan-soft: #b9f2ff;
--amber: #ffb45c;
--panel: rgba(5, 18, 30, 0.82);
--border: rgba(116, 221, 255, 0.22);
--muted: #8ca9b8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #123149 0%, #081722 42%, #030910 100%);
color: #edfaff;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(0, 0, 0, 0.16), transparent 24%),
radial-gradient(circle, transparent 48%, rgba(0, 0, 0, 0.42) 100%);
}
header {
position: absolute;
top: 24px;
left: 26px;
z-index: 4;
max-width: 520px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
font-weight: 680;
letter-spacing: -0.045em;
line-height: 1.04;
}
header p {
max-width: 450px;
margin: 10px 0 0;
color: #a5c0ce;
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin-top: 14px;
color: #9cb7c5;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(116, 221, 255, 0.65);
}
.dot.low {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 180, 92, 0.65);
}
.panel {
position: absolute;
top: 96px;
right: 22px;
z-index: 5;
width: 340px;
padding: 17px;
overflow: hidden;
border: 1px solid var(--border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(13, 38, 55, 0.94), var(--panel));
box-shadow:
0 22px 60px rgba(0, 0, 0, 0.36),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-title h2 {
margin: 0;
font-size: 13px;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.live::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px var(--cyan);
content: "";
}
.chart-wrap {
position: relative;
margin: 0 -3px 10px;
border: 1px solid rgba(116, 221, 255, 0.11);
border-radius: 12px;
background: rgba(1, 10, 18, 0.34);
overflow: hidden;
}
.chart-wrap svg {
display: block;
width: 100%;
height: 118px;
}
.chart-caption {
position: absolute;
top: 7px;
left: 10px;
color: #698797;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 12px 0 7px;
color: #a9c0cc;
font-size: 11px;
}
output {
color: var(--cyan-soft);
font-variant-numeric: tabular-nums;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0 14px;
appearance: none;
border-radius: 10px;
outline: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--range, 50%),
rgba(116, 221, 255, 0.14) var(--range, 50%),
rgba(116, 221, 255, 0.14) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #09202f;
border-radius: 50%;
background: var(--cyan-soft);
box-shadow: 0 0 0 1px var(--cyan), 0 0 13px rgba(116, 221, 255, 0.5);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #09202f;
border-radius: 50%;
background: var(--cyan-soft);
box-shadow: 0 0 0 1px var(--cyan), 0 0 13px rgba(116, 221, 255, 0.5);
cursor: pointer;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 8px;
}
.stat {
min-width: 0;
padding: 10px 9px;
border: 1px solid rgba(116, 221, 255, 0.1);
border-radius: 10px;
background: rgba(3, 15, 24, 0.42);
}
.stat span {
display: block;
margin-bottom: 5px;
color: #7897a6;
font-size: 9px;
font-weight: 720;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
display: block;
overflow: hidden;
color: var(--cyan-soft);
font-size: 14px;
font-variant-numeric: tabular-nums;
text-overflow: ellipsis;
white-space: nowrap;
}
.stat.throat strong {
color: var(--amber);
}
.equation {
margin-top: 12px;
padding: 10px 11px;
border-left: 2px solid var(--cyan);
border-radius: 0 8px 8px 0;
background: rgba(116, 221, 255, 0.045);
color: #c2d8e2;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
line-height: 1.7;
}
.equation b {
color: var(--cyan-soft);
font-weight: 650;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 12px;
}
button {
flex: 1;
padding: 8px 10px;
border: 1px solid rgba(116, 221, 255, 0.17);
border-radius: 9px;
background: rgba(116, 221, 255, 0.065);
color: #b8d2de;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
button:hover {
border-color: rgba(116, 221, 255, 0.4);
background: rgba(116, 221, 255, 0.12);
}
#annotations {
position: absolute;
inset: 0;
z-index: 3;
pointer-events: none;
}
.tap-label {
position: absolute;
top: 0;
left: 0;
min-width: 132px;
padding: 9px 11px;
border: 1px solid rgba(116, 221, 255, 0.3);
border-radius: 10px;
background: rgba(3, 16, 27, 0.88);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
color: #dff7ff;
will-change: transform;
}
.tap-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 18px;
background: linear-gradient(var(--cyan), transparent);
content: "";
}
.tap-label.low {
border-color: rgba(255, 180, 92, 0.48);
}
.tap-label.low::after {
background: linear-gradient(var(--amber), transparent);
}
.tap-label .tag {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.tap-label.low .tag {
color: var(--amber);
}
.tap-label strong {
display: block;
margin: 2px 0 4px;
font-size: 11px;
}
.tap-label b {
color: var(--cyan-soft);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.tap-label.low b {
color: #ffd09a;
}
.axis-label {
position: absolute;
top: 0;
left: 0;
padding: 5px 9px;
border: 1px solid rgba(116, 221, 255, 0.14);
border-radius: 20px;
background: rgba(3, 16, 27, 0.64);
color: #7897a6;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
white-space: nowrap;
text-transform: uppercase;
will-change: transform;
}
.hint {
position: absolute;
bottom: 22px;
left: 50%;
z-index: 4;
padding: 8px 12px;
border: 1px solid rgba(116, 221, 255, 0.12);
border-radius: 20px;
background: rgba(3, 14, 23, 0.55);
color: #7897a6;
font-size: 10px;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.loading {
position: absolute;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #06101a;
color: var(--cyan);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 16px;
left: 16px;
max-width: calc(100% - 32px);
}
header p {
display: none;
}
h1 {
font-size: 26px;
}
.legend {
margin-top: 9px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 48vh;
padding: 13px;
overflow-y: auto;
border-radius: 15px;
}
.chart-wrap svg {
height: 88px;
}
.stats {
gap: 5px;
}
.stat {
padding: 8px 7px;
}
.stat strong {
font-size: 12px;
}
.equation {
font-size: 10px;
}
.hint {
display: none;
}
.tap-label {
min-width: 105px;
padding: 7px 8px;
}
.tap-label strong {
font-size: 9px;
}
.tap-label b {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene"></canvas>
<div class="vignette"></div>
<header>
<div class="eyebrow">Interactive fluid mechanics</div>
<h1>Venturi pressure drop</h1>
<p>
A horizontal, low-poly Venturi tube under ideal incompressible flow.
The smaller throat accelerates the fluid, lowering its static pressure.
</p>
<div class="legend">
<span><i class="dot"></i> Higher pressure</span>
<span><i class="dot low"></i> Throat pressure minimum</span>
<span>Ideal flow · ρ = 1000 kg/m³</span>
</div>
</header>
<aside class="panel">
<div class="panel-title">
<h2>Bernoulli model</h2>
<span class="live">Live</span>
</div>
<div class="chart-wrap">
<span class="chart-caption">Static pressure along tube</span>
<svg viewBox="0 0 280 92" role="img" aria-label="Pressure profile along the Venturi tube">
<defs>
<linearGradient id="areaGradient" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#74ddff" stop-opacity="0.26" />
<stop offset="100%" stop-color="#74ddff" stop-opacity="0.015" />
</linearGradient>
</defs>
<line x1="10" y1="78" x2="270" y2="78" stroke="#315064" stroke-width="1" />
<line id="referenceLine" x1="10" x2="270" stroke="#497487"
stroke-width="1" stroke-dasharray="4 5" opacity="0.75" />
<text id="referenceText" x="266" y="17" text-anchor="end"
fill="#678797" font-size="7">101.3 kPa outlet reference</text>
<path id="pressureArea" fill="url(#areaGradient)" />
<path id="pressureLine" fill="none" stroke="#74ddff" stroke-width="2.2"
stroke-linecap="round" stroke-linejoin="round" />
<circle id="throatDot" r="4" fill="#ffb45c" stroke="#ffe1b9" stroke-width="1.2" />
<text x="10" y="89" fill="#567584" font-size="7">INLET</text>
<text x="140" y="89" text-anchor="middle" fill="#567584" font-size="7">THROAT</text>
<text x="270" y="89" text-anchor="end" fill="#567584" font-size="7">OUTLET</text>
</svg>
</div>
<label class="control-label" for="flow">
<span>Inlet velocity</span>
<output id="flowValue">2.4 m/s</output>
</label>
<input id="flow" type="range" min="1" max="3.2" step="0.1" value="2.4" />
<div class="stats">
<div class="stat">
<span>Inlet p₁</span>
<strong id="statP1">101.3 kPa</strong>
</div>
<div class="stat throat">
<span>Throat pₜ</span>
<strong id="statPt">58.1 kPa</strong>
</div>
<div class="stat">
<span>Outlet p₂</span>
<strong id="statP2">101.3 kPa</strong>
</div>
</div>
<div class="equation">
<b>p + ½ρv² + ρgz = constant</b><br />
A₁v₁ = Aₜvₜ<br />
vₜ = <span id="throatVelocity">9.6</span> m/s ·
Δp = <span id="pressureDrop">43.2</span> kPa
</div>
<div class="buttons">
<button id="pauseFlow" type="button">Pause flow</button>
<button id="resetView" type="button">Reset camera</button>
</div>
</aside>
<div id="annotations">
<div id="labelP1" class="tap-label">
<span class="tag">Tap A₁</span>
<strong>Inlet · high pressure</strong>
<b id="labelP1Value">101.3 kPa</b>
</div>
<div id="labelPt" class="tap-label low">
<span class="tag">Tap Aₜ</span>
<strong>Throat · low pressure</strong>
<b id="labelPtValue">58.1 kPa</b>
</div>
<div id="labelP2" class="tap-label">
<span class="tag">Tap A₂</span>
<strong>Outlet · high pressure</strong>
<b id="labelP2Value">101.3 kPa</b>
</div>
<div id="axisLabel" class="axis-label">Horizontal reference · Δz = 0</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="loading" class="loading">Loading Three.js scene</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x06101a, 0.018);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Camera controls are intentionally implemented without Three.js addons.
const controls = {
target: new THREE.Vector3(0.7, 0.15, 0),
radius: window.innerWidth < 760 ? 29 : 17.5,
theta: 0.57,
phi: 1.13,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.radius = window.innerWidth < 760 ? 29 : 17.5;
controls.theta = 0.57;
controls.phi = 1.13;
controls.target.set(0.7, 0.15, 0);
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.28,
1.46
);
});
function endDrag(event) {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
10,
34
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#resetView").addEventListener("click", resetCamera);
// Lighting
scene.add(new THREE.HemisphereLight(0xb9ecff, 0x07101a, 2.25));
const keyLight = new THREE.DirectionalLight(0xd9f6ff, 3.1);
keyLight.position.set(-4, 9, 7);
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x27bde9, 18, 28, 2);
rimLight.position.set(4, 2, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa64f, 7, 16, 2);
warmLight.position.set(-1.5, 3.5, 4);
scene.add(warmLight);
// Venturi geometry
const MAIN_RADIUS = 1.36;
const THROAT_RADIUS = 0.68;
const TUBE_START = -7.5;
const TUBE_END = 7.5;
const profile = [
{ x: -7.5, r: MAIN_RADIUS },
{ x: -5.5, r: MAIN_RADIUS },
{ x: -3.6, r: 1.02 },
{ x: -2.2, r: THROAT_RADIUS },
{ x: 0.6, r: THROAT_RADIUS },
{ x: 2.3, r: 1.02 },
{ x: 4.8, r: MAIN_RADIUS },
{ x: 7.5, r: MAIN_RADIUS }
];
function radiusAt(x) {
if (x <= profile[0].x) return profile[0].r;
if (x >= profile[profile.length - 1].x) {
return profile[profile.length - 1].r;
}
for (let i = 1; i < profile.length; i++) {
const a = profile[i - 1];
const b = profile[i];
if (x >= a.x && x <= b.x) {
const t = (x - a.x) / (b.x - a.x);
return THREE.MathUtils.lerp(a.r, b.r, t);
}
}
return MAIN_RADIUS;
}
function makeTubeGeometry(radialSegments, ringCount, radiusScale = 1) {
const positions = [];
const indices = [];
for (let i = 0; i <= ringCount; i++) {
const x = THREE.MathUtils.lerp(TUBE_START, TUBE_END, i / ringCount);
const radius = radiusAt(x) * radiusScale;
for (let j = 0; j <= radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
positions.push(
x,
Math.cos(angle) * radius,
Math.sin(angle) * radius
);
}
}
const stride = radialSegments + 1;
for (let i = 0; i < ringCount; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * stride + j;
const b = a + 1;
const c = a + stride;
const d = c + 1;
indices.push(a, b, c);
indices.push(b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const shell = new THREE.Mesh(
makeTubeGeometry(14, 56),
new THREE.MeshStandardMaterial({
color: 0x65c8eb,
transparent: true,
opacity: 0.27,
roughness: 0.25,
metalness: 0.12,
flatShading: true,
side: THREE.DoubleSide,
depthWrite: false
})
);
shell.renderOrder = 2;
scene.add(shell);
const fluidVolume = new THREE.Mesh(
makeTubeGeometry(14, 56, 0.9),
new THREE.MeshBasicMaterial({
color: 0x1188ae,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
})
);
fluidVolume.renderOrder = 1;
scene.add(fluidVolume);
// Longitudinal low-poly ribs
const ribMaterial = new THREE.LineBasicMaterial({
color: 0x9feaff,
transparent: true,
opacity: 0.56
});
for (let rib = 0; rib < 7; rib++) {
const angle = (rib / 7) * Math.PI * 2;
const points = [];
for (let i = 0; i <= 64; i++) {
const x = THREE.MathUtils.lerp(TUBE_START, TUBE_END, i / 64);
const r = radiusAt(x) + 0.012;
points.push(
new THREE.Vector3(
x,
Math.cos(angle) * r,
Math.sin(angle) * r
)
);
}
const ribLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
ribMaterial
);
scene.add(ribLine);
}
// Structural rings
const ringXs = [-7.5, -5.5, -3.6, -2.2, -0.7, 0.6, 2.3, 4.8, 7.5];
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0xb0edff,
emissive: 0x174b63,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.72,
roughness: 0.38,
metalness: 0.38,
flatShading: true
});
ringXs.forEach((x) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radiusAt(x), 0.027, 4, 14),
ringMaterial
);
ring.rotation.y = Math.PI / 2;
ring.position.x = x;
scene.add(ring);
});
// End caps
const capMaterial = new THREE.MeshBasicMaterial({
color: 0x73d9f7,
transparent: true,
opacity: 0.09,
side: THREE.DoubleSide,
depthWrite: false
});
[TUBE_START, TUBE_END].forEach((x) => {
const cap = new THREE.Mesh(
new THREE.CircleGeometry(MAIN_RADIUS, 14),
capMaterial
);
cap.rotation.y = Math.PI / 2;
cap.position.x = x;
scene.add(cap);
});
// Pressure taps
function addPressureTap(x, color) {
const radius = radiusAt(x);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.3,
roughness: 0.34,
metalness: 0.48,
flatShading: true
});
const stemHeight = 0.82;
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, stemHeight, 8),
material
);
stem.position.set(x, radius + stemHeight / 2, 0);
scene.add(stem);
const flange = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.08, 10),
material
);
flange.position.set(x, radius + 0.04, 0);
scene.add(flange);
const sensor = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.12, 0),
material
);
sensor.position.set(x, radius + stemHeight + 0.09, 0);
scene.add(sensor);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.095, 0.025, 4, 10),
material
);
collar.rotation.x = Math.PI / 2;
collar.position.set(x, radius + 0.65, 0);
scene.add(collar);
}
addPressureTap(-5.5, 0x65ddff);
addPressureTap(-0.8, 0xffb45c);
addPressureTap(5.5, 0x65ddff);
// Floor and grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x06101a,
roughness: 0.95,
metalness: 0,
transparent: true,
opacity: 0.72
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.7;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x1d536c, 0x0d2939);
grid.position.y = -2.67;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
// Horizontal elevation reference
const dimensionPoints = [
new THREE.Vector3(TUBE_START, -2.13, 0),
new THREE.Vector3(TUBE_END, -2.13, 0),
new THREE.Vector3(TUBE_START, -2.28, 0),
new THREE.Vector3(TUBE_START, -1.98, 0),
new THREE.Vector3(TUBE_END, -2.28, 0),
new THREE.Vector3(TUBE_END, -1.98, 0)
];
const dimensionGeometry = new THREE.BufferGeometry().setFromPoints(
dimensionPoints
);
const dimensionLine = new THREE.Line(
dimensionGeometry,
new THREE.LineDashedMaterial({
color: 0x4c839b,
transparent: true,
opacity: 0.58,
dashSize: 0.14,
gapSize: 0.08
})
);
dimensionLine.computeLineDistances();
scene.add(dimensionLine);
// Flow arrows inside the tube
function makeFlowArrow(length) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0xc4f7ff,
transparent: true,
opacity: 0.56,
depthWrite: false
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.022, length, 6),
material
);
shaft.rotation.z = -Math.PI / 2;
shaft.position.x = length / 2;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.24, 6),
material
);
head.rotation.z = -Math.PI / 2;
head.position.x = length + 0.1;
group.add(head);
return group;
}
const inletArrow = makeFlowArrow(0.72);
inletArrow.position.set(-6.05, 0, 0);
scene.add(inletArrow);
const throatArrow = makeFlowArrow(1.25);
throatArrow.position.set(-1.7, 0, 0);
scene.add(throatArrow);
const outletArrow = makeFlowArrow(0.72);
outletArrow.position.set(4.55, 0, 0);
scene.add(outletArrow);
// Instanced low-poly flow particles
const particleCount = 120;
const particleGeometry = new THREE.IcosahedronGeometry(0.066, 0);
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.88
});
const particles = new THREE.InstancedMesh(
particleGeometry,
particleMaterial,
particleCount
);
particles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
particles.frustumCulled = false;
const particleData = [];
for (let i = 0; i < particleCount; i++) {
particleData.push({
distance: Math.random() * (TUBE_END - TUBE_START),
angle: Math.random() * Math.PI * 2,
radial: Math.sqrt(Math.random()) * 0.72
});
const color = new THREE.Color().lerpColors(
new THREE.Color(0x3bbde8),
new THREE.Color(0xc5fbff),
Math.random() * 0.8
);
particles.setColorAt(i, color);
}
particles.instanceColor.needsUpdate = true;
scene.add(particles);
const dummy = new THREE.Object3D();
const state = {
inletVelocity: 2.4,
paused: false,
density: 1000,
outletPressure: 101325,
areaRatio: (THROAT_RADIUS / MAIN_RADIUS) ** 2
};
function velocityAt(x) {
const localAreaRatio =
(THROAT_RADIUS * THROAT_RADIUS) /
(radiusAt(x) * radiusAt(x));
return state.inletVelocity * localAreaRatio;
}
function pressureAt(x) {
const v = velocityAt(x);
const outletVelocity = velocityAt(TUBE_END);
return (
state.outletPressure +
0.5 * state.density * (outletVelocity ** 2 - v ** 2)
);
}
function formatPressure(pa) {
return `${(pa / 1000).toFixed(1)} kPa`;
}
function updatePressureChart() {
const points = [];
const left = 10;
const right = 270;
const bottom = 78;
const top = 8;
const maxPressure = 130000;
for (let i = 0; i <= 80; i++) {
const x = THREE.MathUtils.lerp(TUBE_START, TUBE_END, i / 80);
const px = THREE.MathUtils.lerp(left, right, i / 80);
const py = bottom -
(pressureAt(x) / maxPressure) * (bottom - top);
points.push([px, py]);
}
const path = points
.map(([x, y], index) =>
`${index === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)}`
)
.join(" ");
document.querySelector("#pressureLine").setAttribute("d", path);
document.querySelector("#pressureArea").setAttribute(
"d",
`${path} L${right},${bottom} L${left},${bottom} Z`
);
const referenceY =
bottom -
(state.outletPressure / maxPressure) * (bottom - top);
document
.querySelector("#referenceLine")
.setAttribute("y1", referenceY);
document
.querySelector("#referenceLine")
.setAttribute("y2", referenceY);
document
.querySelector("#referenceText")
.setAttribute("y", Math.max(12, referenceY - 5));
const throatX =
left +
((-0.8 - TUBE_START) / (TUBE_END - TUBE_START)) * (right - left);
const throatY = bottom -
(pressureAt(-0.8) / maxPressure) * (bottom - top);
const dot = document.querySelector("#throatDot");
dot.setAttribute("cx", throatX);
dot.setAttribute("cy", throatY);
}
function updateModel() {
const vi = state.inletVelocity;
const vt = vi / state.areaRatio;
const pressureDrop =
0.5 * state.density * (vt ** 2 - vi ** 2);
const throatPressure = state.outletPressure - pressureDrop;
document.querySelector("#flowValue").textContent =
`${vi.toFixed(1)} m/s`;
document.querySelector("#throatVelocity").textContent =
vt.toFixed(1);
document.querySelector("#pressureDrop").textContent =
(pressureDrop / 1000).toFixed(1);
const inletText = formatPressure(state.outletPressure);
const throatText = formatPressure(throatPressure);
const outletText = formatPressure(state.outletPressure);
document.querySelector("#statP1").textContent = inletText;
document.querySelector("#statPt").textContent = throatText;
document.querySelector("#statP2").textContent = outletText;
document.querySelector("#labelP1Value").textContent = inletText;
document.querySelector("#labelPtValue").textContent = throatText;
document.querySelector("#labelP2Value").textContent = outletText;
inletArrow.scale.x = 0.78 + vi * 0.11;
outletArrow.scale.x = 0.78 + vi * 0.11;
throatArrow.scale.x = 0.72 + vt * 0.052;
updatePressureChart();
}
const flowInput = document.querySelector("#flow");
function updateRangeFill() {
const min = Number(flowInput.min);
const max = Number(flowInput.max);
const value = Number(flowInput.value);
const percentage = ((value - min) / (max - min)) * 100;
flowInput.style.setProperty("--range", `${percentage}%`);
}
flowInput.addEventListener("input", () => {
state.inletVelocity = Number(flowInput.value);
updateRangeFill();
updateModel();
});
const pauseButton = document.querySelector("#pauseFlow");
pauseButton.addEventListener("click", () => {
state.paused = !state.paused;
pauseButton.textContent = state.paused ? "Resume flow" : "Pause flow";
});
// Screen-space annotation positioning
const annotationData = [
{
element: document.querySelector("#labelP1"),
position: new THREE.Vector3(-5.5, radiusAt(-5.5) + 1.42, 0)
},
{
element: document.querySelector("#labelPt"),
position: new THREE.Vector3(-0.8, radiusAt(-0.8) + 1.38, 0)
},
{
element: document.querySelector("#labelP2"),
position: new THREE.Vector3(5.5, radiusAt(5.5) + 1.42, 0)
},
{
element: document.querySelector("#axisLabel"),
position: new THREE.Vector3(0, -2.16, 0)
}
];
const projected = new THREE.Vector3();
function positionAnnotations() {
annotationData.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate3d(${x.toFixed(1)}px, ${y.toFixed(1)}px, 0) ` +
"translate(-50%, -100%)";
element.style.opacity = projected.z > 1 ? "0" : "1";
});
}
function updateParticles(dt) {
const span = TUBE_END - TUBE_START;
for (let i = 0; i < particleCount; i++) {
const seed = particleData[i];
const x = TUBE_START + seed.distance;
const localVelocity = velocityAt(x);
if (!state.paused) {
seed.distance += localVelocity * dt * 0.52;
if (seed.distance > span) seed.distance -= span;
}
const particleX = TUBE_START + seed.distance;
const radius = radiusAt(particleX) * seed.radial * 0.82;
dummy.position.set(
particleX,
Math.cos(seed.angle) * radius,
Math.sin(seed.angle) * radius
);
const speedScale = 0.78 + localVelocity / 12;
dummy.scale.setScalar(speedScale);
dummy.updateMatrix();
particles.setMatrixAt(i, dummy.matrix);
}
particles.instanceMatrix.needsUpdate = true;
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = width < 760 ? 52 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
updateRangeFill();
updateModel();
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
updateParticles(dt);
updateCamera();
positionAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
</script>
</body>
</html>
```