Prompt specification
Build or customize the Three.js 3D scene "Reynolds-number dimension explorer" 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: Reynolds-number dimension explorer
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reynolds-number-dimension-explorer-x1468
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring laminar and turbulent flow. Provide density, speed, length, and viscosity inputs with units; calculate the dimensionless ratio and show illustrative patterns while avoiding one universal transition threshold for all geometries. Low-poly.
Working Three.js Starter (reynolds-number-dimension-explorer-x1468):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Reynolds Explorer — Low-Poly Flow Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111d;
--panel: rgba(9, 20, 34, 0.9);
--panel-edge: rgba(126, 208, 238, 0.2);
--text: #e9f7ff;
--muted: #8da9ba;
--cyan: #38d9ff;
--violet: #a06cff;
--amber: #ffa23a;
--line: rgba(137, 200, 225, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 35%, #10293b 0, transparent 42%),
linear-gradient(145deg, #07111d, #040912 75%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 16px;
left: 16px;
width: min(370px, calc(100vw - 32px));
max-height: calc(100vh - 32px);
overflow-y: auto;
padding: 18px;
border: 1px solid var(--panel-edge);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.42),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
}
.brand-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.brand {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
}
.badge {
padding: 4px 8px;
border: 1px solid rgba(56, 217, 255, 0.25);
border-radius: 999px;
color: #aeefff;
background: rgba(56, 217, 255, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
}
h1 {
margin: 10px 0 5px;
font-size: 27px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.lede {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section-label {
margin: 16px 0 9px;
color: #b9d0dd;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
select,
input[type="number"] {
min-width: 0;
height: 37px;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
background: rgba(5, 13, 23, 0.86);
color: var(--text);
}
select {
padding: 0 28px 0 10px;
}
input[type="number"] {
width: 100%;
padding: 0 9px;
font-variant-numeric: tabular-nums;
}
select:focus,
input:focus {
border-color: rgba(56, 217, 255, 0.65);
box-shadow: 0 0 0 3px rgba(56, 217, 255, 0.08);
}
#geometry {
width: 100%;
}
.small {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.fields {
display: grid;
gap: 10px;
}
.field-title {
display: block;
margin-bottom: 5px;
color: #b9d0dd;
font-size: 11px;
}
.input-unit {
display: grid;
grid-template-columns: minmax(0, 1fr) 108px;
gap: 7px;
}
.derived {
margin-top: 16px;
padding: 15px;
border: 1px solid rgba(112, 192, 224, 0.2);
border-radius: 13px;
background:
linear-gradient(145deg, rgba(26, 64, 84, 0.3), rgba(7, 18, 31, 0.55));
}
.derived-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
#reSymbol {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
font-weight: 800;
}
.status {
padding: 4px 8px;
border-radius: 999px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.status.laminar {
color: #9eeeff;
background: rgba(56, 217, 255, 0.12);
}
.status.transition {
color: #d2c1ff;
background: rgba(160, 108, 255, 0.14);
}
.status.turbulent {
color: #ffd19a;
background: rgba(255, 162, 58, 0.13);
}
#reValue {
margin-top: 8px;
font-size: 35px;
font-weight: 760;
line-height: 1;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
#formula {
min-height: 31px;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
font-variant-numeric: tabular-nums;
}
.eq {
color: #d9f5ff;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 700;
}
.gauge {
position: relative;
height: 9px;
margin: 15px 0 7px;
overflow: visible;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
#gaugeBand {
position: absolute;
top: 0;
bottom: 0;
border-radius: inherit;
background: linear-gradient(
90deg,
rgba(160, 108, 255, 0.8),
rgba(210, 113, 255, 0.95)
);
box-shadow: 0 0 12px rgba(160, 108, 255, 0.28);
}
#gaugeMarker {
position: absolute;
top: 50%;
width: 3px;
height: 19px;
border-radius: 3px;
background: white;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
transform: translate(-50%, -50%);
transition: left 180ms ease;
}
.gauge-captions {
display: flex;
justify-content: space-between;
color: #6f8b9c;
font-size: 9px;
}
#basisDetail {
margin-top: 11px;
color: #b8ceda;
font-size: 10px;
line-height: 1.45;
}
#guideText {
margin: 9px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
margin-top: 14px;
}
button {
min-height: 37px;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #dff6ff;
cursor: pointer;
font-size: 10px;
font-weight: 700;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(56, 217, 255, 0.42);
background: rgba(56, 217, 255, 0.08);
}
button:active {
transform: translateY(1px);
}
.notice {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #7893a4;
font-size: 10px;
line-height: 1.5;
}
.notice strong {
color: #a9c4d2;
}
.legend {
position: fixed;
z-index: 8;
right: 18px;
bottom: 18px;
width: 245px;
padding: 13px 14px;
border: 1px solid var(--panel-edge);
border-radius: 13px;
background: rgba(7, 17, 29, 0.78);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 8px;
color: #cce9f5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend-scale {
display: flex;
align-items: center;
gap: 7px;
color: #8da9ba;
font-size: 9px;
}
.legend-scale i {
display: block;
width: 15px;
height: 4px;
border-radius: 4px;
}
.legend-scale .c1 { background: var(--cyan); }
.legend-scale .c2 { background: var(--violet); }
.legend-scale .c3 { background: var(--amber); }
.legend p {
margin: 9px 0 0;
color: #708c9d;
font-size: 9px;
line-height: 1.45;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #07111d;
color: #9cdff0;
font-size: 12px;
letter-spacing: 0.08em;
}
@media (max-width: 720px) {
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 52vh;
padding: 15px;
}
.legend {
top: 12px;
right: 12px;
bottom: auto;
width: 205px;
}
h1 {
font-size: 23px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly flow visualization"></div>
<div id="loading">LOADING THREE.JS…</div>
<aside class="panel">
<div class="brand-row">
<span class="brand">FLOW / LAB</span>
<span class="badge">LOW-POLY • ILLUSTRATIVE</span>
</div>
<h1>Reynolds Explorer</h1>
<p class="lede">
Change the fluid and test geometry to inspect a procedural flow pattern.
The tracer field is an illustration, not a CFD solution.
</p>
<label class="section-label" for="geometry">Test geometry</label>
<select id="geometry">
<option value="pipe">Smooth circular pipe</option>
<option value="duct">Rectangular duct — 4:1 aspect</option>
<option value="plate">Flat plate — zero pressure gradient</option>
</select>
<p id="geometryHint" class="small"></p>
<div class="section-label">Fluid and geometry inputs</div>
<div class="fields">
<div class="field">
<label class="field-title" for="rho">Density ρ</label>
<div class="input-unit">
<input id="rho" type="number" min="0.001" step="0.1" value="998">
<select id="rhoUnit" aria-label="Density unit">
<option value="kgm3">kg/m³</option>
<option value="gcm3">g/cm³</option>
</select>
</div>
</div>
<div class="field">
<label class="field-title" for="velocity">Mean speed v</label>
<div class="input-unit">
<input id="velocity" type="number" min="0" step="0.01" value="0.18">
<select id="velocityUnit" aria-label="Speed unit">
<option value="ms">m/s</option>
<option value="kmh">km/h</option>
<option value="fts">ft/s</option>
</select>
</div>
</div>
<div class="field">
<label class="field-title" id="lengthLabel" for="length">Pipe diameter D</label>
<div class="input-unit">
<input id="length" type="number" min="0.001" step="0.1" value="14">
<select id="lengthUnit" aria-label="Length unit">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m">m</option>
<option value="in">in</option>
</select>
</div>
</div>
<div class="field">
<label class="field-title" for="viscosity">Dynamic viscosity μ</label>
<div class="input-unit">
<input id="viscosity" type="number" min="0.000001" step="0.1" value="1">
<select id="viscosityUnit" aria-label="Viscosity unit">
<option value="mPas">mPa·s</option>
<option value="Pas">Pa·s</option>
<option value="cp">cP</option>
</select>
</div>
</div>
</div>
<div class="derived" aria-live="polite">
<div class="derived-top">
<span id="reSymbol">Re_D</span>
<span id="status" class="status transition">Transition-sensitive</span>
</div>
<div id="reValue">—</div>
<div id="formula"></div>
<div class="gauge" aria-label="Geometry-specific transition guide">
<div id="gaugeBand"></div>
<div id="gaugeMarker"></div>
</div>
<div class="gauge-captions">
<span>lower guide</span>
<span>transition</span>
<span>higher guide</span>
</div>
<div id="basisDetail"></div>
<p id="guideText"></p>
</div>
<div class="buttons">
<button id="pause" type="button" aria-pressed="false">Pause flow</button>
<button id="reseed" type="button">Re-seed</button>
<button id="resetCamera" type="button">Reset view</button>
</div>
<div class="notice">
<strong>No universal transition threshold is used.</strong>
Geometry, aspect ratio, roughness, inlet disturbances, pressure gradient,
and flow history all affect transition. The displayed bands are contextual
guides for the selected geometry.
</div>
</aside>
<div class="legend">
<div class="legend-title">Procedural tracer field</div>
<div class="legend-scale">
<i class="c1"></i>
<span>ordered</span>
<i class="c2"></i>
<span>mixing</span>
<i class="c3"></i>
<span>disturbed</span>
</div>
<p>
Low-poly arrows indicate local tracer direction and relative speed.
Drag to orbit; scroll to zoom. Double-click to reset the camera.
</p>
</div>
<noscript>This scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const TAU = Math.PI * 2;
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
const smoothstep = (a, b, value) => {
const t = clamp((value - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
};
const geometryConfig = {
pipe: {
name: "Smooth circular pipe",
symbol: "Re_D",
lengthLabel: "Pipe diameter D",
basisText: "The length input is the internal pipe diameter D.",
low: 2300,
high: 4000,
gaugeMin: 0,
gaugeMax: 8000,
blendStart: 1800,
blendEnd: 4200,
labels: ["Laminar guide", "Transition-sensitive", "Turbulent guide"],
guide:
"For a smooth, straight circular pipe, commonly cited guides place " +
"sustained laminar flow below Re_D ≈ 2,300 and fully turbulent flow " +
"above ≈ 4,000. Entry disturbances, roughness, vibration, and " +
"compressibility can move the observed transition."
},
duct: {
name: "Rectangular duct — 4:1 aspect",
symbol: "Re_Dh",
lengthLabel: "Hydraulic diameter D_h",
basisText:
"The length input is the hydraulic diameter D_h of an illustrative 4:1 duct.",
low: 1700,
high: 3500,
gaugeMin: 0,
gaugeMax: 7000,
blendStart: 1400,
blendEnd: 3800,
labels: ["Laminar guide", "Transition-sensitive", "Turbulent guide"],
guide:
"A smooth 4:1 rectangular duct is often discussed with a disturbance-" +
"sensitive range around Re_Dh ≈ 1,700–3,500. This is not a universal " +
"cutoff: aspect ratio, roughness, pressure gradient, and inlet conditions " +
"can substantially change it."
},
plate: {
name: "Flat plate — zero pressure gradient",
symbol: "Re_L",
lengthLabel: "Plate chord L",
basisText:
"The length input is the plate chord L. Re_L is not itself a local transition criterion.",
low: 300000,
high: 1000000,
gaugeMin: 10000,
gaugeMax: 2000000,
blendStart: 250000,
blendEnd: 1100000,
labels: ["Pre-transition guide", "Transition-sensitive", "Post-transition guide"],
guide:
"For a smooth, low-turbulence flat plate in zero pressure gradient, " +
"transition is often associated with a local Re_x near 5×10⁵ rather " +
"than one plate-length threshold. Free-stream turbulence, heating, " +
"pressure gradient, and surface conditions can move it substantially."
}
};
let currentGeometry = "pipe";
let currentSI = {
density: 998,
speed: 0.18,
length: 0.014,
viscosity: 0.001
};
let regimeBlend = 0;
let paused = false;
const stage = $("stage");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
$("loading").textContent = "WebGL could not be initialized.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.setClearColor(0x000000, 0);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111d, 0.028);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.42,
phi: 1.18,
radius: 12.2,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0x9de7ff, 0x07101a, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.1);
keyLight.position.set(3, 7, 5);
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x20bfff, 16, 18, 2);
cyanLight.position.set(-4, 1, 3);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0x8f54ff, 11, 15, 2);
violetLight.position.set(4, -1, -2);
scene.add(violetLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(36, 36),
new THREE.MeshStandardMaterial({
color: 0x07101a,
roughness: 1,
metalness: 0,
transparent: true,
opacity: 0.72
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.62;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x1d5067, 0x102735);
grid.position.y = -1.60;
grid.material.transparent = true;
grid.material.opacity = 0.43;
scene.add(grid);
const shellGroup = new THREE.Group();
scene.add(shellGroup);
const tracerCount = 900;
const tracerGeometry = new THREE.ConeGeometry(0.045, 0.24, 4, 1);
tracerGeometry.rotateZ(-Math.PI / 2);
const tracerMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.5,
metalness: 0.06,
emissive: 0x041823,
emissiveIntensity: 0.7
});
const tracers = new THREE.InstancedMesh(
tracerGeometry,
tracerMaterial,
tracerCount
);
tracers.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
tracers.frustumCulled = false;
scene.add(tracers);
const dummy = new THREE.Object3D();
const direction = new THREE.Vector3();
const axisX = new THREE.Vector3(1, 0, 0);
const cyanColor = new THREE.Color(0x38d9ff);
const violetColor = new THREE.Color(0xa06cff);
const amberColor = new THREE.Color(0xffa23a);
const particleColor = new THREE.Color();
const particles = Array.from({ length: tracerCount }, () => ({
offset: Math.random(),
radius: Math.sqrt(Math.random()) * 0.93,
angle: Math.random() * TAU,
yN: (Math.random() * 2 - 1) * 0.88,
zN: (Math.random() * 2 - 1) * 0.90,
height: 0.04 + Math.pow(Math.random(), 0.75) * 0.92,
phase: Math.random() * TAU,
seed: Math.random() * 100,
size: 0.65 + Math.random() * 0.62,
px: 0,
py: 0,
pz: 0,
hasPrev: false
}));
function seedParticles(resetDistance = false) {
for (const p of particles) {
p.offset = Math.random();
p.radius = Math.sqrt(Math.random()) * 0.93;
p.angle = Math.random() * TAU;
p.yN = (Math.random() * 2 - 1) * 0.88;
p.zN = (Math.random() * 2 - 1) * 0.90;
p.height = 0.04 + Math.pow(Math.random(), 0.75) * 0.92;
p.phase = Math.random() * TAU;
p.seed = Math.random() * 100;
p.size = 0.65 + Math.random() * 0.62;
p.hasPrev = false;
}
if (resetDistance) flowDistance = 0;
}
function clearShell() {
const geometries = new Set();
const materials = new Set();
shellGroup.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
const list = Array.isArray(object.material)
? object.material
: [object.material];
list.forEach((material) => materials.add(material));
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
shellGroup.clear();
}
function addShellMesh(geometry, material, position) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
shellGroup.add(mesh);
return mesh;
}
function addEdges(geometry, material) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
material
);
shellGroup.add(edges);
return edges;
}
function buildShell(kind) {
clearShell();
const length = 7.8;
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0x2a6a83,
emissive: 0x071d29,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.17,
roughness: 0.78,
metalness: 0.08,
side: THREE.DoubleSide,
depthWrite: false
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x64bad3,
transparent: true,
opacity: 0.48
});
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x4d8ca2,
emissive: 0x0a2632,
emissiveIntensity: 0.6,
roughness: 0.65,
metalness: 0.15
});
if (kind === "pipe") {
const geometry = new THREE.CylinderGeometry(
1.2, 1.2, length, 12, 1, true
);
geometry.rotateZ(Math.PI / 2);
addShellMesh(geometry, shellMaterial);
addEdges(geometry, edgeMaterial);
for (const x of [-length / 2, length / 2]) {
const ringGeometry = new THREE.TorusGeometry(1.2, 0.032, 4, 12);
ringGeometry.rotateY(Math.PI / 2);
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
ring.position.x = x;
shellGroup.add(ring);
}
} else if (kind === "duct") {
const geometry = new THREE.BoxGeometry(length, 0.76, 3.04);
addShellMesh(geometry, shellMaterial);
addEdges(geometry, edgeMaterial);
const ribGeometry = new THREE.BoxGeometry(0.055, 0.82, 3.10);
for (const x of [-length / 2, length / 2]) {
const rib = new THREE.Mesh(ribGeometry, ringMaterial);
rib.position.x = x;
shellGroup.add(rib);
}
} else {
const geometry = new THREE.BoxGeometry(length, 0.09, 3.0);
const material = new THREE.MeshStandardMaterial({
color: 0x4a687c,
emissive: 0x07141e,
emissiveIntensity: 0.35,
roughness: 0.72,
metalness: 0.15
});
const plate = addShellMesh(
geometry,
material,
new THREE.Vector3(0, -0.58, 0)
);
plate.addEdges?.();
const plateEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0x75a6ba,
transparent: true,
opacity: 0.6
})
);
plateEdges.position.copy(plate.position);
shellGroup.add(plateEdges);
}
const axisY = kind === "plate" ? -0.49 : 0;
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-4.18, axisY, 0),
new THREE.Vector3(4.18, axisY, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x6ebbd1,
dashSize: 0.14,
gapSize: 0.09,
transparent: true,
opacity: 0.48
})
);
axis.computeLineDistances();
shellGroup.add(axis);
for (const p of particles) p.hasPrev = false;
}
buildShell(currentGeometry);
const unitFactors = {
density: {
kgm3: 1,
gcm3: 1000
},
speed: {
ms: 1,
kmh: 1 / 3.6,
fts: 0.3048
},
length: {
mm: 0.001,
cm: 0.01,
m: 1,
in: 0.0254
},
viscosity: {
mPas: 0.001,
Pas: 1,
cp: 0.001
}
};
function readNumber(id) {
const value = Number.parseFloat($(id).value);
return Number.isFinite(value) ? value : NaN;
}
function getSIValues() {
const density =
readNumber("rho") *
unitFactors.density[$("rhoUnit").value];
const speed =
readNumber("velocity") *
unitFactors.speed[$("velocityUnit").value];
const length =
readNumber("length") *
unitFactors.length[$("lengthUnit").value];
const viscosity =
readNumber("viscosity") *
unitFactors.viscosity[$("viscosityUnit").value];
if (
!Number.isFinite(density) ||
!Number.isFinite(speed) ||
!Number.isFinite(length) ||
!Number.isFinite(viscosity) ||
density <= 0 ||
speed < 0 ||
length <= 0 ||
viscosity <= 0
) {
return null;
}
return { density, speed, length, viscosity };
}
function formatNumber(value, digits = 0) {
return value.toLocaleString(undefined, {
maximumFractionDigits: digits
});
}
function gaugePosition(value, config) {
if (config.gaugeMin > 0) {
const min = config.gaugeMin;
const max = config.gaugeMax;
const t =
(Math.log10(Math.max(value, min)) - Math.log10(min)) /
(Math.log10(max) - Math.log10(min));
return clamp(t, 0, 1) * 100;
}
return clamp(
(value - config.gaugeMin) / (config.gaugeMax - config.gaugeMin),
0,
1
) * 100;
}
function updateReadout() {
const config = geometryConfig[currentGeometry];
const values = getSIValues();
$("lengthLabel").textContent = config.lengthLabel;
$("geometryHint").textContent = config.basisText;
$("basisDetail").textContent = config.basisText;
$("guideText").textContent = config.guide;
$("reSymbol").textContent = config.symbol;
if (!values) {
currentSI = null;
regimeBlend = 0;
$("reValue").textContent = "—";
$("formula").textContent = "Enter positive, finite values.";
$("status").textContent = "Invalid input";
$("status").className = "status transition";
return;
}
currentSI = values;
const re =
(values.density * values.speed * values.length) /
values.viscosity;
regimeBlend = smoothstep(
config.blendStart,
config.blendEnd,
re
);
let state = "laminar";
if (re >= config.high) state = "turbulent";
else if (re >= config.low) state = "transition";
$("reValue").textContent = formatNumber(re);
$("status").textContent = config.labels[
state === "laminar" ? 0 : state === "transition" ? 1 : 2
];
$("status").className = `status ${state}`;
$("formula").innerHTML =
`<span class="eq">Re = ρvL/μ</span><br>` +
`(${formatNumber(values.density, 2)} kg/m³ × ` +
`${formatNumber(values.speed, 3)} m/s × ` +
`${formatNumber(values.length, 5)} m) / ` +
`${formatNumber(values.viscosity, 5)} Pa·s`;
const lowPosition = gaugePosition(config.low, config);
const highPosition = gaugePosition(config.high, config);
const markerPosition = gaugePosition(re, config);
$("gaugeBand").style.left = `${lowPosition}%`;
$("gaugeBand").style.width = `${highPosition - lowPosition}%`;
$("gaugeMarker").style.left = `${markerPosition}%`;
}
$("geometry").addEventListener("change", () => {
currentGeometry = $("geometry").value;
buildShell(currentGeometry);
updateReadout();
});
for (const id of [
"rho",
"rhoUnit",
"velocity",
"velocityUnit",
"length",
"lengthUnit",
"viscosity",
"viscosityUnit"
]) {
$(id).addEventListener("input", updateReadout);
$(id).addEventListener("change", updateReadout);
}
$("pause").addEventListener("click", () => {
paused = !paused;
$("pause").textContent = paused ? "Resume flow" : "Pause flow";
$("pause").setAttribute("aria-pressed", String(paused));
});
$("reseed").addEventListener("click", () => {
seedParticles(true);
});
function resetCamera() {
cameraState.theta = 0.42;
cameraState.phi = 1.18;
cameraState.radius = 12.2;
cameraState.target.set(0, 0, 0);
updateCamera();
}
$("resetCamera").addEventListener("click", resetCamera);
let flowDistance = 0;
let visualTime = 0;
function updateTracers(dt) {
const blend = regimeBlend;
for (let i = 0; i < tracerCount; i++) {
const p = particles[i];
const u = (p.offset + flowDistance) % 1;
const x = -3.82 + u * 7.64;
const n1 =
Math.sin(u * 33 + p.phase + visualTime * 2.15);
const n2 =
Math.sin(u * 71 - p.phase * 1.7 + visualTime * 4.35);
const n3 =
Math.sin(
p.seed * 17.13 +
Math.floor(visualTime * 1.6) * 2.31
);
const envelope = 0.25 + 0.75 * u;
let disturbance =
(0.012 + 0.105 * blend + 0.24 * blend * blend) *
envelope;
let y;
let z;
let profile;
if (currentGeometry === "pipe") {
const radius = p.radius;
const y0 = radius * 1.06 * Math.cos(p.angle);
const z0 = radius * 1.06 * Math.sin(p.angle);
profile = 1 - 0.58 * radius * radius;
y =
y0 * (0.96 + 0.04 * profile) +
disturbance * (n1 * 0.72 + n3 * 0.28);
z =
z0 * (0.96 + 0.04 * profile) +
disturbance * (n2 * 0.78 + n1 * 0.22);
const radialDistance = Math.hypot(y, z);
if (radialDistance > 1.08) {
const correction = 1.08 / radialDistance;
y *= correction;
z *= correction;
}
} else if (currentGeometry === "duct") {
profile =
(1 - p.yN * p.yN) *
(1 - 0.45 * p.zN * p.zN);
y =
p.yN * 0.34 +
disturbance * (n1 * 0.7 + n3 * 0.3);
z =
p.zN * 1.42 +
disturbance * (n2 * 0.78 + n1 * 0.22);
y = clamp(y, -0.35, 0.35);
z = clamp(z, -1.45, 1.45);
} else {
const boundaryThickness = 0.10 + 0.28 * u;
const exponent = THREE.MathUtils.lerp(0.50, 0.34, blend);
profile = Math.min(
1,
Math.pow(
p.height / Math.max(boundaryThickness, 0.04),
exponent
)
);
y =
-0.55 + p.height +
disturbance * 0.32 * (n1 * 0.7 + n3 * 0.3);
z =
p.zN * 1.38 +
disturbance * 0.28 * (n2 * 0.8 + n1 * 0.2);
y = clamp(y, -0.50, 0.46);
z = clamp(z, -1.43, 1.43);
}
if (!p.hasPrev) {
p.px = x;
p.py = y;
p.pz = z;
p.hasPrev = true;
direction.set(1, 0, 0);
} else {
const dx = x - p.px;
const dy = y - p.py;
const dz = z - p.pz;
if (dx < 0 || dx * dx + dy * dy + dz * dz < 1e-10) {
direction.set(1, 0, 0);
} else {
direction.set(dx / dt, dy / dt, dz / dt).normalize();
}
p.px = x;
p.py = y;
p.pz = z;
}
dummy.position.set(x, y, z);
dummy.quaternion.setFromUnitVectors(axisX, direction);
const scale =
p.size * (0.82 + 0.34 * profile);
dummy.scale.set(
scale,
scale * (0.86 + 0.30 * profile),
scale
);
dummy.updateMatrix();
tracers.setMatrixAt(i, dummy.matrix);
if (blend < 0.52) {
particleColor
.copy(cyanColor)
.lerp(violetColor, blend / 0.52);
} else {
particleColor
.copy(violetColor)
.lerp(amberColor, (blend - 0.52) / 0.48);
}
particleColor.offsetHSL(
0,
0,
(profile - 0.5) * 0.10
);
tracers.setColorAt(i, particleColor);
}
tracers.instanceMatrix.needsUpdate = true;
if (tracers.instanceColor) {
tracers.instanceColor.needsUpdate = true;
}
}
// Direct camera controls: pointer drag orbits and wheel zooms.
// No controls addon is used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(
cameraState.phi + dy * 0.006,
0.20,
Math.PI - 0.20
);
updateCamera();
});
function endDrag(event) {
dragging = false;
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("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.8,
23
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateReadout();
let previousTime = performance.now();
renderer.setAnimationLoop((now) => {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused && currentSI) {
const animationRate = clamp(currentSI.speed * 1.2, 0, 2.2);
flowDistance += dt * animationRate * 0.09;
visualTime += dt * animationRate * 1.45;
}
updateTracers(Math.max(dt, 0.0001));
renderer.render(scene, camera);
});
$("loading").style.display = "none";
</script>
</body>
</html>
```