Prompt specification
Build or customize the Three.js 3D scene "Viscous shear parameter 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: Viscous shear parameter explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/viscous-shear-parameter-explorer-x1520
Scene Description Prompt:
Allow plate speed, gap, and viscosity changes in a simple Couette-flow model; display the linear velocity profile and shear stress under its ideal assumptions. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (viscous-shear-parameter-explorer-x1520):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Couette Flow Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07101d;
--panel: rgba(13, 23, 40, 0.92);
--panel-2: rgba(20, 33, 54, 0.78);
--border: rgba(148, 163, 184, 0.16);
--text: #edf5ff;
--muted: #91a4bc;
--cyan: #45d9e8;
--blue: #5297ff;
--orange: #ffad45;
--green: #5ee6a8;
--shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--text);
background:
radial-gradient(circle at 12% 8%, rgba(55, 135, 255, 0.14), transparent 30%),
radial-gradient(circle at 92% 90%, rgba(43, 209, 225, 0.09), transparent 30%),
var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
.app {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.topbar {
min-height: 72px;
padding: 14px 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
border-bottom: 1px solid var(--border);
background: rgba(5, 12, 23, 0.72);
backdrop-filter: blur(18px);
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(69, 217, 232, 0.38);
border-radius: 12px;
background: linear-gradient(145deg, rgba(69, 217, 232, 0.2), rgba(82, 151, 255, 0.08));
box-shadow: inset 0 0 20px rgba(69, 217, 232, 0.08);
overflow: hidden;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 7px;
right: 7px;
height: 4px;
border-radius: 99px;
transform: skewX(-24deg);
}
.brand-mark::before {
top: 11px;
background: var(--orange);
}
.brand-mark::after {
top: 22px;
background: var(--cyan);
}
h1 {
margin: 0;
font-size: 19px;
line-height: 1.1;
letter-spacing: -0.02em;
}
.subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 12px;
}
.top-status {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
justify-content: flex-end;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 999px;
color: #c5d3e5;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
}
.chip.live {
color: #b9f7da;
border-color: rgba(94, 230, 168, 0.24);
background: rgba(94, 230, 168, 0.07);
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px var(--green);
animation: pulse 1.8s infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.8);
}
}
.workspace {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: 300px minmax(420px, 1fr) 340px;
gap: 14px;
padding: 14px;
}
.panel,
.stage {
min-height: 0;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
overflow: hidden;
}
.panel {
padding: 18px;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18px;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #dce9f8;
}
.section-number {
color: #52667f;
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.control {
margin-bottom: 22px;
}
.control-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 10px;
}
.control label {
font-size: 13px;
font-weight: 650;
color: #d6e3f3;
}
output {
color: var(--cyan);
font: 700 13px ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
border-radius: 99px;
outline: none;
background:
linear-gradient(90deg, var(--cyan) var(--fill, 50%), rgba(148, 163, 184, 0.16) var(--fill, 50%));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #0c1728;
border-radius: 50%;
background: #dffcff;
box-shadow: 0 0 0 1px rgba(69, 217, 232, 0.8), 0 0 14px rgba(69, 217, 232, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #0c1728;
border-radius: 50%;
background: #dffcff;
box-shadow: 0 0 0 1px rgba(69, 217, 232, 0.8), 0 0 14px rgba(69, 217, 232, 0.35);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #61748d;
font-size: 10px;
}
.preset-title {
margin: 26px 0 10px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.preset-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.preset,
.camera-button {
border: 1px solid var(--border);
border-radius: 10px;
color: #c9d7e8;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition: 160ms ease;
}
.preset {
padding: 9px 5px;
font-size: 11px;
font-weight: 650;
}
.preset:hover,
.camera-button:hover {
color: #fff;
border-color: rgba(69, 217, 232, 0.4);
background: rgba(69, 217, 232, 0.08);
transform: translateY(-1px);
}
.camera-button {
width: 100%;
margin-top: 18px;
padding: 10px 12px;
font-size: 12px;
font-weight: 650;
}
.assumptions {
margin-top: 24px;
padding: 14px;
border: 1px solid rgba(69, 217, 232, 0.13);
border-radius: 13px;
background: rgba(69, 217, 232, 0.035);
}
.assumptions h3 {
margin: 0 0 10px;
color: #c9f9fc;
font-size: 12px;
}
.assumptions ul {
display: grid;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
}
.assumptions li {
position: relative;
padding-left: 15px;
color: #8fa4bc;
font-size: 11px;
line-height: 1.45;
}
.assumptions li::before {
content: "";
position: absolute;
top: 0.52em;
left: 0;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px rgba(69, 217, 232, 0.55);
}
.stage {
position: relative;
background: #091321;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-top {
position: absolute;
top: 14px;
left: 14px;
right: 14px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.scene-label {
padding: 9px 11px;
border: 1px solid rgba(148, 163, 184, 0.13);
border-radius: 10px;
background: rgba(7, 16, 29, 0.68);
backdrop-filter: blur(12px);
color: #aabbd0;
font-size: 10px;
line-height: 1.55;
}
.scene-label strong {
color: #eff8ff;
font-size: 11px;
}
.scene-label .cyan {
color: var(--cyan);
}
.scene-label .orange {
color: var(--orange);
}
.scene-help {
text-align: right;
color: #70839b;
}
.scene-bottom {
position: absolute;
left: 14px;
right: 14px;
bottom: 14px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.velocity-legend {
width: 210px;
padding: 10px 11px;
border: 1px solid rgba(148, 163, 184, 0.13);
border-radius: 10px;
background: rgba(7, 16, 29, 0.68);
backdrop-filter: blur(12px);
color: #8498b1;
font-size: 10px;
}
.legend-bar {
height: 6px;
margin: 7px 0 5px;
border-radius: 99px;
background: linear-gradient(90deg, #4c8fff, #45d9e8, #ffad45);
}
.legend-labels {
display: flex;
justify-content: space-between;
}
.scene-equation {
padding: 9px 11px;
border: 1px solid rgba(148, 163, 184, 0.13);
border-radius: 10px;
background: rgba(7, 16, 29, 0.68);
backdrop-filter: blur(12px);
color: #9fb1c8;
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
#loading {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: #8ea4bd;
background: #091321;
font-size: 12px;
z-index: 4;
}
.stress-card {
padding: 15px;
border: 1px solid rgba(255, 173, 69, 0.17);
border-radius: 14px;
background:
radial-gradient(circle at 90% 0%, rgba(255, 173, 69, 0.12), transparent 45%),
rgba(255, 173, 69, 0.035);
}
.metric-label {
color: #91a4bc;
font-size: 11px;
font-weight: 650;
}
.stress-main {
display: flex;
align-items: baseline;
gap: 7px;
margin: 7px 0 2px;
}
.stress-main strong {
color: #ffd092;
font: 750 31px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.04em;
}
.stress-main span {
color: #b89464;
font-size: 13px;
}
.signed-stress {
color: #7f93aa;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.stress-track {
height: 5px;
margin-top: 13px;
overflow: hidden;
border-radius: 99px;
background: rgba(148, 163, 184, 0.13);
}
#stressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--orange));
transition: width 180ms ease;
}
.stress-scale {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #60748d;
font-size: 9px;
}
.metrics-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 10px;
}
.metric-box {
padding: 11px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.metric-box strong {
display: block;
margin-top: 5px;
color: #e8f3ff;
font: 700 15px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.profile-card {
margin-top: 22px;
padding: 14px 12px 10px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(255, 255, 255, 0.022);
}
.profile-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 0 4px;
}
.profile-head h3 {
margin: 0;
font-size: 12px;
}
.linear-tag {
padding: 4px 7px;
border-radius: 999px;
color: #9aeef4;
background: rgba(69, 217, 232, 0.08);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
}
.profile-card svg {
display: block;
width: 100%;
height: auto;
margin-top: 6px;
overflow: visible;
}
.profile-grid {
stroke: rgba(148, 163, 184, 0.12);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.profile-axis {
stroke: rgba(174, 197, 222, 0.35);
stroke-width: 1;
}
#profileLine {
fill: none;
stroke: var(--cyan);
stroke-width: 3;
stroke-linecap: round;
filter: drop-shadow(0 0 5px rgba(69, 217, 232, 0.3));
}
.profile-dot {
fill: #dffcff;
stroke: var(--cyan);
stroke-width: 2;
}
.svg-text {
fill: #788da6;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.formula-box {
margin-top: 10px;
padding: 12px;
border-left: 2px solid var(--cyan);
border-radius: 0 9px 9px 0;
background: rgba(69, 217, 232, 0.045);
color: #9eb1c8;
font: 10px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.formula-box strong {
color: #d9f8fb;
}
.note {
margin-top: 15px;
color: #71859e;
font-size: 10px;
line-height: 1.55;
}
@media (max-width: 1120px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
}
.workspace {
grid-template-columns: 280px minmax(420px, 1fr);
grid-template-areas:
"controls stage"
"results results";
}
.controls-panel {
grid-area: controls;
}
.stage {
grid-area: stage;
min-height: 660px;
}
.results-panel {
grid-area: results;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 18px;
}
.results-panel .section-heading {
grid-column: 1 / -1;
margin-bottom: 0;
}
.profile-card {
margin-top: 0;
}
}
@media (max-width: 720px) {
.topbar {
align-items: flex-start;
flex-direction: column;
}
.top-status {
justify-content: flex-start;
}
.workspace {
display: flex;
flex-direction: column;
}
.stage {
order: -1;
min-height: 56vh;
}
.results-panel {
display: block;
}
.profile-card {
margin-top: 20px;
}
.scene-help {
display: none;
}
.scene-equation {
display: none;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Couette Flow Lab</h1>
<div class="subtitle">Interactive ideal plate-driven viscous flow</div>
</div>
</div>
<div class="top-status">
<span class="chip live"><span class="live-dot"></span> LIVE MODEL</span>
<span class="chip">Newtonian fluid</span>
<span class="chip">No pressure gradient</span>
</div>
</header>
<main class="workspace">
<aside class="panel controls-panel">
<div class="section-heading">
<h2>Model parameters</h2>
<span class="section-number">01</span>
</div>
<div class="control">
<div class="control-head">
<label for="speed">Lower plate speed</label>
<output id="speedValue" for="speed">0.50 m/s</output>
</div>
<input id="speed" type="range" min="0" max="2" step="0.01" value="0.5" />
<div class="range-ends">
<span>0 m/s</span>
<span>2 m/s</span>
</div>
</div>
<div class="control">
<div class="control-head">
<label for="gap">Plate gap</label>
<output id="gapValue" for="gap">1.5 mm</output>
</div>
<input id="gap" type="range" min="0.5" max="5" step="0.1" value="1.5" />
<div class="range-ends">
<span>0.5 mm</span>
<span>5.0 mm</span>
</div>
</div>
<div class="control">
<div class="control-head">
<label for="viscosity">Dynamic viscosity</label>
<output id="viscosityValue" for="viscosity">10.0 mPa·s</output>
</div>
<input id="viscosity" type="range" min="1" max="100" step="0.5" value="10" />
<div class="range-ends">
<span>1 mPa·s</span>
<span>100 mPa·s</span>
</div>
</div>
<div class="preset-title">Quick presets</div>
<div class="preset-grid">
<button class="preset" data-preset="water">Water-like</button>
<button class="preset" data-preset="oil">Oil-like</button>
<button class="preset" data-preset="syrup">Syrup-like</button>
</div>
<button class="camera-button" id="resetCamera">Reset camera</button>
<div class="assumptions">
<h3>Ideal assumptions</h3>
<ul>
<li>Steady, fully developed, laminar flow</li>
<li>Constant-viscosity Newtonian fluid</li>
<li>Parallel infinite flat plates</li>
<li>No pressure gradient along the plates</li>
<li>No-slip at both plate surfaces</li>
</ul>
</div>
</aside>
<section class="stage">
<div id="viewport" aria-label="Interactive 3D Couette flow visualization"></div>
<div id="loading">Loading Three.js visualization…</div>
<div class="scene-top">
<div class="scene-label">
<strong>Couette velocity field</strong><br />
<span class="orange">Lower plate: moving</span> ·
<span class="cyan">Upper plate: stationary</span><br />
Gap: <span id="sceneGap">1.5 mm</span> · U:
<span id="sceneSpeed">0.50 m/s</span>
</div>
<div class="scene-label scene-help">
Drag to orbit<br />
Scroll to zoom · Double-click to reset
</div>
</div>
<div class="scene-bottom">
<div class="velocity-legend">
Local velocity magnitude
<div class="legend-bar"></div>
<div class="legend-labels">
<span>0 m/s</span>
<span id="legendMax">0.50 m/s</span>
</div>
</div>
<div class="scene-equation">
u(y) = U(1 − y/h) | τ = μU/h = constant
</div>
</div>
</section>
<aside class="panel results-panel">
<div class="section-heading">
<h2>Flow results</h2>
<span class="section-number">02</span>
</div>
<div>
<div class="stress-card">
<div class="metric-label">Wall shear stress magnitude</div>
<div class="stress-main">
<strong id="stressValue">3.33</strong>
<span>Pa</span>
</div>
<div class="signed-stress">
τ<sub>xy</sub> = <span id="signedStress">−3.33 Pa</span>
</div>
<div class="stress-track">
<div id="stressFill"></div>
</div>
<div class="stress-scale">
<span>0 Pa</span>
<span>log scale · 400 Pa full range</span>
</div>
</div>
<div class="metrics-grid">
<div class="metric-box">
<div class="metric-label">Shear rate |du/dy|</div>
<strong id="shearRate">333 s⁻¹</strong>
</div>
<div class="metric-box">
<div class="metric-label">Velocity gradient</div>
<strong id="gradient">−333 s⁻¹</strong>
</div>
</div>
</div>
<div class="profile-card">
<div class="profile-head">
<h3>Normalized velocity profile</h3>
<span class="linear-tag">LINEAR</span>
</div>
<svg viewBox="0 0 320 225" role="img" aria-label="Linear Couette velocity profile">
<defs>
<linearGradient id="profileGradient" x1="0" x2="1">
<stop offset="0%" stop-color="#45d9e8" stop-opacity="0.03" />
<stop offset="100%" stop-color="#45d9e8" stop-opacity="0.20" />
</linearGradient>
</defs>
<line class="profile-grid" x1="52" y1="66.5" x2="286" y2="66.5" />
<line class="profile-grid" x1="52" y1="109" x2="286" y2="109" />
<line class="profile-grid" x1="52" y1="151.5" x2="286" y2="151.5" />
<line class="profile-axis" x1="52" y1="24" x2="52" y2="190" />
<line class="profile-axis" x1="52" y1="190" x2="286" y2="190" />
<path id="profileArea" fill="url(#profileGradient)" />
<path id="profileLine" d="M 52 24 L 286 190" />
<g id="profileDots"></g>
<text class="svg-text" x="58" y="17">0 · top plate</text>
<text class="svg-text" id="svgBottomU" x="286" y="207" text-anchor="end">
U = 0.50 m/s
</text>
<text class="svg-text" x="24" y="190">0</text>
<text class="svg-text" x="18" y="107" transform="rotate(-90 18 107)">y</text>
<text class="svg-text" x="168" y="220" text-anchor="middle">u / U</text>
</svg>
<div class="formula-box">
<strong>Velocity profile</strong><br />
<span id="profileEquation">u(y) = 0.50 × (1 − y/1.5 mm)</span><br /><br />
<strong>Shear stress</strong><br />
τ = μU/h · magnitude = μU/h<br />
τ<sub>xy</sub> = −μU/h for upward y
</div>
</div>
<div class="note">
The 3D gap is enlarged schematically for visibility; all displayed stresses,
shear rates, and profile values use the selected physical gap.
</div>
</aside>
</main>
</div>
<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 state = {
speed: 0.5,
gap: 1.5,
viscosity: 10
};
const speedInput = $("speed");
const gapInput = $("gap");
const viscosityInput = $("viscosity");
const viewport = $("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091321);
scene.fog = new THREE.Fog(0x091321, 15, 31);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Three-dimensional Couette flow scene");
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9dcff, 0x182235, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.5);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4eddea, 1.15);
rimLight.position.set(-7, 4, -6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 34),
new THREE.MeshStandardMaterial({
color: 0x08111e,
roughness: 0.94,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.34;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(22, 28, 0x24435c, 0x14283b);
grid.position.y = -0.325;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const lowerPlate = new THREE.Mesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xb8681f,
emissive: 0x321300,
emissiveIntensity: 0.35,
metalness: 0.48,
roughness: 0.3
})
);
lowerPlate.castShadow = true;
lowerPlate.receiveShadow = true;
scene.add(lowerPlate);
const upperPlate = new THREE.Mesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0x66758a,
emissive: 0x10202c,
emissiveIntensity: 0.2,
metalness: 0.62,
roughness: 0.28
})
);
upperPlate.castShadow = true;
upperPlate.receiveShadow = true;
scene.add(upperPlate);
const plateLength = 11.4;
const plateDepth = 6.7;
const plateThickness = 0.3;
const voxelColumns = 16;
const voxelRows = 7;
const voxelDepth = 5;
const voxelSpanX = 10.5;
const voxelSpanZ = 5.4;
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.32,
metalness: 0.08,
transparent: true,
opacity: 0.93
});
const voxelCount = voxelColumns * voxelRows * voxelDepth;
const voxels = new THREE.InstancedMesh(unitBox, voxelMaterial, voxelCount);
voxels.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
voxels.castShadow = true;
voxels.receiveShadow = true;
scene.add(voxels);
const chamberOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(11.05, 1, 6.05)),
new THREE.LineBasicMaterial({
color: 0x5bdcff,
transparent: true,
opacity: 0.24
})
);
scene.add(chamberOutline);
const velocityArrowGroup = new THREE.Group();
scene.add(velocityArrowGroup);
const movingArrowGroup = new THREE.Group();
scene.add(movingArrowGroup);
const movingArrows = [];
for (let i = 0; i < 4; i++) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-5 + i * 2.6, 0.08, 3.52),
1.25,
0xffb04b,
0.28,
0.2
);
movingArrowGroup.add(arrow);
movingArrows.push(arrow);
}
const cameraState = {
azimuth: 0.72,
polar: 1.04,
radius: 12.8,
target: new THREE.Vector3(0, 0.8, 0)
};
let dragging = false;
let previousX = 0;
let previousY = 0;
let worldGap = 1.6;
let flowPhase = 0;
const dummy = new THREE.Object3D();
function modulo(value, divisor) {
return ((value % divisor) + divisor) % divisor;
}
function velocityColor(fraction) {
const color = new THREE.Color();
color.setHSL(0.56 - 0.48 * fraction, 0.82, 0.56);
return color;
}
function updateCamera() {
const { azimuth, polar, radius, target } = cameraState;
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.azimuth = 0.72;
cameraState.polar = 1.04;
cameraState.radius = 12.8;
cameraState.target.set(0, worldGap * 0.5, 0);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= deltaX * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - deltaY * 0.005,
0.34,
1.46
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.5,
23
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
$("resetCamera").addEventListener("click", resetCamera);
function updateVoxelColors() {
let index = 0;
for (let row = 0; row < voxelRows; row++) {
const fraction = 1 - (row + 0.5) / voxelRows;
const color = velocityColor(fraction);
for (let column = 0; column < voxelColumns; column++) {
for (let depth = 0; depth < voxelDepth; depth++) {
voxels.setColorAt(index, color);
index++;
}
}
}
if (voxels.instanceColor) voxels.instanceColor.needsUpdate = true;
}
function updateVoxelMatrices() {
const blockX = (voxelSpanX / voxelColumns) * 0.72;
const blockY = (worldGap / voxelRows) * 0.70;
const blockZ = (voxelSpanZ / voxelDepth) * 0.72;
let index = 0;
for (let row = 0; row < voxelRows; row++) {
const fraction = 1 - (row + 0.5) / voxelRows;
const shift = flowPhase * fraction;
for (let column = 0; column < voxelColumns; column++) {
const baseX =
-voxelSpanX / 2 +
(column + 0.5) * (voxelSpanX / voxelColumns);
const animatedX =
modulo(baseX + shift + voxelSpanX / 2, voxelSpanX) - voxelSpanX / 2;
for (let depth = 0; depth < voxelDepth; depth++) {
const z =
-voxelSpanZ / 2 +
(depth + 0.5) * (voxelSpanZ / voxelDepth);
dummy.position.set(
animatedX,
(row + 0.5) * (worldGap / voxelRows),
z
);
dummy.scale.set(blockX, blockY, blockZ);
dummy.updateMatrix();
voxels.setMatrixAt(index, dummy.matrix);
index++;
}
}
}
voxels.instanceMatrix.needsUpdate = true;
}
function clearVelocityArrows() {
for (const arrow of [...velocityArrowGroup.children]) {
velocityArrowGroup.remove(arrow);
arrow.line.geometry.dispose();
arrow.line.material.dispose();
arrow.cone.geometry.dispose();
arrow.cone.material.dispose();
}
}
function updateVelocityArrows() {
clearVelocityArrows();
for (let row = 0; row < voxelRows; row++) {
const fraction = 1 - (row + 0.5) / voxelRows;
const length = Math.max(0.001, 5.1 * fraction * (state.speed / 2));
const color = velocityColor(fraction);
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(
-5.15,
(row + 0.5) * (worldGap / voxelRows),
-3.62
),
length,
color,
Math.min(0.32, length * 0.35),
Math.min(0.2, length * 0.22)
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.9;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.92;
velocityArrowGroup.add(arrow);
}
}
function updateGeometry() {
const normalizedGap = (state.gap - 0.5) / 4.5;
worldGap = THREE.MathUtils.lerp(1.45, 3.65, normalizedGap);
lowerPlate.scale.set(plateLength, plateThickness, plateDepth);
lowerPlate.position.set(0, -plateThickness * 0.5, 0);
upperPlate.scale.set(plateLength, plateThickness, plateDepth);
upperPlate.position.set(0, worldGap + plateThickness * 0.5, 0);
chamberOutline.geometry.dispose();
chamberOutline.geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(11.05, worldGap, 6.05)
);
chamberOutline.position.set(0, worldGap * 0.5, 0);
cameraState.target.y = worldGap * 0.5;
updateVoxelColors();
updateVoxelMatrices();
updateVelocityArrows();
updateCamera();
}
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateProfile(speed) {
const left = 52;
const right = 286;
const top = 24;
const bottom = 190;
const linePath =
speed === 0
? `M ${left} ${top} L ${left} ${bottom}`
: `M ${left} ${top} L ${right} ${bottom}`;
const areaPath =
speed === 0
? `M ${left} ${top} L ${left} ${bottom} L ${left} ${bottom} Z`
: `M ${left} ${top} L ${right} ${bottom} L ${left} ${bottom} Z`;
$("profileLine").setAttribute("d", linePath);
$("profileArea").setAttribute("d", areaPath);
let dots = "";
for (let i = 0; i <= 6; i++) {
const fraction = i / 6;
const y = top + fraction * (bottom - top);
const normalizedVelocity = fraction;
const x =
speed === 0
? left
: left + normalizedVelocity * (right - left);
dots += `<circle class="profile-dot" cx="${x}" cy="${y}" r="3.5"></circle>`;
}
$("profileDots").innerHTML = dots;
$("svgBottomU").textContent = `U = ${speed.toFixed(2)} m/s`;
}
function updateModel() {
state.speed = Number(speedInput.value);
state.gap = Number(gapInput.value);
state.viscosity = Number(viscosityInput.value);
const gapMeters = state.gap * 1e-3;
const viscosityPaSeconds = state.viscosity * 1e-3;
const shearRate = state.speed / gapMeters;
const signedStress = -viscosityPaSeconds * shearRate;
const stressMagnitude = Math.abs(signedStress);
$("speedValue").textContent = `${state.speed.toFixed(2)} m/s`;
$("gapValue").textContent = `${state.gap.toFixed(1)} mm`;
$("viscosityValue").textContent = `${state.viscosity.toFixed(1)} mPa·s`;
$("sceneSpeed").textContent = `${state.speed.toFixed(2)} m/s`;
$("sceneGap").textContent = `${state.gap.toFixed(1)} mm`;
$("legendMax").textContent = `${state.speed.toFixed(2)} m/s`;
$("stressValue").textContent = stressMagnitude.toFixed(2);
$("signedStress").textContent = `${signedStress.toFixed(2)} Pa`;
$("shearRate").textContent = `${formatNumber(shearRate)} s⁻¹`;
$("gradient").textContent = `${formatNumber(signedStress / viscosityPaSeconds)} s⁻¹`;
$("profileEquation").textContent =
`u(y) = ${state.speed.toFixed(2)} × (1 − y/${state.gap.toFixed(1)} mm)`;
const logarithmicStress =
stressMagnitude > 0
? Math.max(2, (Math.log10(1 + stressMagnitude) / Math.log10(401)) * 100)
: 0;
$("stressFill").style.width = `${logarithmicStress}%`;
updateRangeFill(speedInput);
updateRangeFill(gapInput);
updateRangeFill(viscosityInput);
updateProfile(state.speed);
updateGeometry();
}
function formatNumber(value) {
if (Math.abs(value) >= 1000) {
return value.toLocaleString(undefined, {
maximumFractionDigits: 0
});
}
if (Math.abs(value) >= 10) {
return value.toFixed(1);
}
return value.toFixed(2);
}
[speedInput, gapInput, viscosityInput].forEach((input) => {
input.addEventListener("input", updateModel);
});
const presets = {
water: { speed: 0.6, gap: 1.0, viscosity: 1 },
oil: { speed: 0.25, gap: 2.0, viscosity: 20 },
syrup: { speed: 0.1, gap: 3.0, viscosity: 100 }
};
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const preset = presets[button.dataset.preset];
speedInput.value = preset.speed;
gapInput.value = preset.gap;
viscosityInput.value = preset.viscosity;
updateModel();
});
});
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
flowPhase = (flowPhase + delta * state.speed * 0.58) % 1000;
updateVoxelMatrices();
for (let i = 0; i < movingArrows.length; i++) {
const x =
-5.3 +
modulo(i * 2.65 + flowPhase * 0.82, 10.6);
movingArrows[i].position.x = x;
}
renderer.render(scene, camera);
}
resizeRenderer();
updateModel();
$("loading").remove();
animate();
</script>
</body>
</html>
```