Prompt specification
Build or customize the Three.js 3D scene "Sliding plates with fluid layer" 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: Sliding plates with fluid layer
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sliding-plates-with-fluid-layer-x1517
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts viscosity and shear in fluids. Build two parallel plates separated by a transparent fluid band and velocity-profile arrows; show shear resistance under a stated Newtonian-fluid assumption. Low-poly.
Working Three.js Starter (sliding-plates-with-fluid-layer-x1517):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Shear Lab — Viscosity and Fluid Motion</title>
<style>
:root {
color-scheme: dark;
--bg: #07111c;
--panel: rgba(8, 21, 35, 0.78);
--line: rgba(166, 213, 233, 0.16);
--text: #eef8ff;
--muted: #91aabd;
--cyan: #56e7e0;
--blue: #4aa9ff;
--orange: #ffb15c;
--coral: #ff766d;
}
* {
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;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 45%, transparent 32%, rgba(1, 7, 14, 0.48) 100%),
linear-gradient(180deg, rgba(2, 9, 16, 0.2), transparent 25%, transparent 75%, rgba(2, 9, 16, 0.45));
z-index: 1;
}
.hero {
position: fixed;
top: 28px;
left: 32px;
z-index: 2;
width: min(560px, calc(100vw - 430px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 34px;
height: 1px;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
h1 {
margin: 0;
max-width: 560px;
font-size: clamp(34px, 4.4vw, 64px);
line-height: 0.96;
letter-spacing: -0.055em;
font-weight: 780;
}
.hero p {
max-width: 510px;
margin: 17px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.hero strong {
color: #dff9ff;
font-weight: 650;
}
.panel {
position: fixed;
top: 24px;
right: 24px;
z-index: 3;
width: 350px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 20px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.35),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(20px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: #284b60 transparent;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-bottom: 15px;
border-bottom: 1px solid var(--line);
}
.panel-head h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.01em;
}
.model-badge {
flex: 0 0 auto;
padding: 5px 8px;
border: 1px solid rgba(86, 231, 224, 0.26);
border-radius: 999px;
color: var(--cyan);
background: rgba(86, 231, 224, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.assumption {
margin: 15px 0 17px;
color: #afc4d3;
font-size: 12px;
line-height: 1.55;
}
.assumption strong {
color: var(--text);
}
.equations {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 18px;
}
.equation {
min-height: 65px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.equation .label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.equation .value {
color: #f5fbff;
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-style: italic;
white-space: nowrap;
}
.equation .value em {
color: var(--cyan);
font-style: normal;
}
.control {
margin: 0 0 15px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.control label {
color: #c7d8e4;
font-size: 11px;
font-weight: 650;
}
.control output {
color: var(--cyan);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
90deg,
rgba(86, 231, 224, 0.85),
rgba(74, 169, 255, 0.22)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #092030;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(86, 231, 224, 0.45), 0 0 14px rgba(86, 231, 224, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #092030;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(86, 231, 224, 0.45);
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.stat {
padding: 9px 8px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.stat span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.stat strong {
display: block;
color: #f0f8ff;
font-size: 12px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 16px;
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
color: #adc2d1;
font-size: 10px;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 14px;
height: 14px;
accent-color: var(--coral);
}
.buttons {
display: flex;
gap: 7px;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
padding: 8px 10px;
color: #dbeaf4;
background: rgba(255, 255, 255, 0.045);
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(86, 231, 224, 0.4);
background: rgba(86, 231, 224, 0.08);
}
.note {
margin: 13px 0 0;
color: #718da0;
font-size: 9px;
line-height: 1.5;
}
.legend {
position: fixed;
left: 32px;
bottom: 28px;
z-index: 2;
display: flex;
flex-wrap: wrap;
gap: 17px;
max-width: calc(100vw - 440px);
padding: 11px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(5, 16, 27, 0.62);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #a8bdcc;
font-size: 10px;
white-space: nowrap;
}
.swatch {
width: 17px;
height: 3px;
border-radius: 99px;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
.swatch.orange {
color: var(--orange);
background: var(--orange);
}
.swatch.coral {
color: var(--coral);
background: var(--coral);
}
.swatch.profile {
color: #e9fbff;
background: #e9fbff;
}
.hint {
position: fixed;
right: 30px;
bottom: 28px;
z-index: 2;
color: rgba(173, 201, 218, 0.62);
font-size: 10px;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--cyan);
background: var(--bg);
font-size: 12px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 820px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.hero h1 {
max-width: 350px;
font-size: 38px;
}
.hero p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 15px;
border-radius: 16px;
}
.equations,
.stats {
display: none;
}
.assumption {
margin: 10px 0 12px;
}
.control {
margin-bottom: 11px;
}
.legend,
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly visualization of shear in a Newtonian fluid"></div>
<div class="vignette"></div>
<header class="hero">
<div class="eyebrow">Fluid mechanics / experiment 01</div>
<h1>Shear, made visible.</h1>
<p>
A moving plate drags a <strong>Newtonian fluid</strong> past a fixed plate.
The linear velocity profile reveals the velocity gradient; the opposing
vectors show the fluid’s shear resistance.
</p>
</header>
<aside class="panel" aria-label="Simulation controls and model information">
<div class="panel-head">
<h2>Couette shear model</h2>
<span class="model-badge">Newtonian</span>
</div>
<p class="assumption">
<strong>Assumption:</strong> constant viscosity, laminar flow, and no-slip
at both plates. Dimensions are visually exaggerated.
</p>
<div class="equations">
<div class="equation">
<span class="label">Velocity profile</span>
<span class="value">u(y) = <em>U y / h</em></span>
</div>
<div class="equation">
<span class="label">Shear law</span>
<span class="value">τ = <em>μ du/dy</em></span>
</div>
</div>
<div class="control">
<div class="control-row">
<label for="speed">Upper plate speed, U</label>
<output id="speedOut" for="speed">1.40 m/s</output>
</div>
<input id="speed" type="range" min="0" max="2.5" step="0.05" value="1.4" />
</div>
<div class="control">
<div class="control-row">
<label for="viscosity">Dynamic viscosity, μ</label>
<output id="viscosityOut" for="viscosity">0.65 Pa·s</output>
</div>
<input id="viscosity" type="range" min="0.05" max="2" step="0.05" value="0.65" />
</div>
<div class="control">
<div class="control-row">
<label for="gap">Plate separation, h</label>
<output id="gapOut" for="gap">2.4 mm</output>
</div>
<input id="gap" type="range" min="1" max="4" step="0.1" value="2.4" />
</div>
<div class="stats" aria-live="polite">
<div class="stat">
<span>Shear rate</span>
<strong id="rateOut">583 s⁻¹</strong>
</div>
<div class="stat">
<span>Shear stress</span>
<strong id="stressOut">379 Pa</strong>
</div>
<div class="stat">
<span>Resistance</span>
<strong id="forceOut">15.2 N</strong>
</div>
</div>
<div class="panel-footer">
<label class="toggle">
<input id="showForces" type="checkbox" checked />
Resistance vectors
</label>
<div class="buttons">
<button id="pause" type="button" aria-pressed="false">Pause</button>
<button id="resetView" type="button">Reset view</button>
</div>
</div>
<p class="note">
Illustrative wetted area A = 0.04 m². Increasing μ or U increases the
required driving force; increasing h reduces the shear rate.
</p>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="swatch"></span>Velocity</div>
<div class="legend-item"><span class="swatch profile"></span>Linear profile</div>
<div class="legend-item"><span class="swatch orange"></span>Applied drive</div>
<div class="legend-item"><span class="swatch coral"></span>Shear resistance</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="loading">Loading Three.js…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const speedInput = document.querySelector("#speed");
const viscosityInput = document.querySelector("#viscosity");
const gapInput = document.querySelector("#gap");
const speedOut = document.querySelector("#speedOut");
const viscosityOut = document.querySelector("#viscosityOut");
const gapOut = document.querySelector("#gapOut");
const rateOut = document.querySelector("#rateOut");
const stressOut = document.querySelector("#stressOut");
const forceOut = document.querySelector("#forceOut");
const showForces = document.querySelector("#showForces");
const pauseButton = document.querySelector("#pause");
const resetViewButton = document.querySelector("#resetView");
const state = {
U: 1.4,
mu: 0.65,
gapMm: 2.4,
paused: false,
showForces: true
};
const AREA = 0.04;
const FLUID_WIDTH = 8.7;
const FLUID_DEPTH = 4.1;
// ------------------------------------------------------------------
// Renderer, scene, camera
// ------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111c);
scene.fog = new THREE.FogExp2(0x07111c, 0.026);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional Newtonian fluid shear demonstration"
);
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0x9eefff, 0x07111a, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x32d9ff, 24, 18, 2);
cyanLight.position.set(-5, 3.5, -3);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff9a4d, 16, 13, 2);
warmLight.position.set(5, 4, 4);
scene.add(warmLight);
// ------------------------------------------------------------------
// Custom camera controls: no external controls module is used.
// ------------------------------------------------------------------
const orbit = {
theta: 0.72,
phi: 1.03,
radius: 12.6,
target: new THREE.Vector3(0, 0.75, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.72;
orbit.phi = 1.03;
orbit.radius = 12.6;
orbit.target.set(0, 0.75, 0);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.32, 1.47);
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7,
19
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetViewButton.addEventListener("click", resetCamera);
// ------------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------------
function addEdges(mesh, color = 0x82c9df, opacity = 0.36) {
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
mesh.add(edges);
return edges;
}
function makeLabel(text, accent = "#56e7e0") {
const canvas = document.createElement("canvas");
canvas.width = 720;
canvas.height = 150;
const ctx = canvas.getContext("2d");
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 710, 140, 24);
ctx.fillStyle = "rgba(5, 17, 29, 0.86)";
ctx.fill();
ctx.fillStyle = accent;
ctx.fillRect(20, 25, 7, 100);
ctx.font = "700 43px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#eef8ff";
ctx.fillText(text, 370, 76);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
const width = Math.min(3.7, 1.55 + text.length * 0.075);
sprite.scale.set(width, width * 0.208, 1);
sprite.renderOrder = 20;
return sprite;
}
const shaftGeometry = new THREE.CylinderGeometry(
0.028,
0.028,
1,
6,
1,
false
);
const headGeometry = new THREE.ConeGeometry(0.09, 0.24, 6, 1, false);
function makeArrow(color, opacity = 1) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.28,
roughness: 0.45,
metalness: 0.08,
transparent: opacity < 1,
opacity
});
const shaft = new THREE.Mesh(shaftGeometry, material);
shaft.rotation.z = -Math.PI / 2;
shaft.castShadow = false;
const head = new THREE.Mesh(headGeometry, material);
head.rotation.z = -Math.PI / 2;
head.castShadow = false;
group.add(shaft, head);
group.userData = { shaft, head, material };
return group;
}
function setArrowLength(arrow, length) {
const { shaft, head } = arrow.userData;
arrow.visible = length > 0.035;
const headLength = Math.min(0.25, Math.max(0.1, length * 0.3));
const shaftLength = Math.max(0.001, length - headLength);
shaft.scale.set(1, shaftLength, 1);
shaft.position.x = shaftLength * 0.5;
head.scale.set(1, headLength / 0.24, 1);
head.position.x = shaftLength + headLength * 0.5;
}
// ------------------------------------------------------------------
// Ground and plates
// ------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
new THREE.MeshStandardMaterial({
color: 0x07131e,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.32;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(22, 44, 0x1d5267, 0x123344);
grid.position.y = -0.309;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(24, 24),
new THREE.ShadowMaterial({ color: 0x00050a, opacity: 0.28 })
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -0.305;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
const bottomPlate = new THREE.Mesh(
new THREE.BoxGeometry(9, 0.28, 4.5),
new THREE.MeshStandardMaterial({
color: 0x172a3b,
roughness: 0.72,
metalness: 0.34,
flatShading: true
})
);
bottomPlate.position.y = -0.14;
bottomPlate.castShadow = true;
bottomPlate.receiveShadow = true;
addEdges(bottomPlate, 0x6c9bb4, 0.3);
scene.add(bottomPlate);
const topPlate = new THREE.Mesh(
new THREE.BoxGeometry(9, 0.28, 4.5),
new THREE.MeshStandardMaterial({
color: 0x263c50,
roughness: 0.62,
metalness: 0.38,
flatShading: true
})
);
topPlate.position.y = 1.55;
topPlate.castShadow = true;
topPlate.receiveShadow = true;
addEdges(topPlate, 0x89bfd3, 0.42);
scene.add(topPlate);
// ------------------------------------------------------------------
// Transparent fluid band and internal layers
// ------------------------------------------------------------------
const fluidMaterial = new THREE.MeshStandardMaterial({
color: 0x30b9d1,
emissive: 0x0d5266,
emissiveIntensity: 0.24,
roughness: 0.22,
metalness: 0.02,
transparent: true,
opacity: 0.13,
depthWrite: false,
side: THREE.DoubleSide
});
const fluidBand = new THREE.Mesh(
new THREE.BoxGeometry(FLUID_WIDTH, 1, FLUID_DEPTH),
fluidMaterial
);
fluidBand.position.y = 0.7;
fluidBand.scale.y = 1.4;
fluidBand.renderOrder = 1;
addEdges(fluidBand, 0x4de8e0, 0.36);
scene.add(fluidBand);
const fluidLayers = [];
const layerMaterial = new THREE.MeshBasicMaterial({
color: 0x59d8e8,
transparent: true,
opacity: 0.035,
depthWrite: false,
side: THREE.DoubleSide
});
for (let i = 1; i < 7; i++) {
const layer = new THREE.Mesh(
new THREE.PlaneGeometry(FLUID_WIDTH - 0.08, FLUID_DEPTH - 0.08),
layerMaterial
);
layer.rotation.x = -Math.PI / 2;
layer.position.y = i / 7;
layer.renderOrder = 2;
scene.add(layer);
fluidLayers.push(layer);
}
// ------------------------------------------------------------------
// Velocity arrows: u(y) = U y / h
// ------------------------------------------------------------------
const velocityArrows = [];
const rowRatios = [1 / 7, 2 / 7, 3 / 7, 4 / 7, 5 / 7, 6 / 7, 1];
const zRows = [-1.58, -0.53, 0.53, 1.58];
for (const ratio of rowRatios) {
for (const z of zRows) {
const color = new THREE.Color().setHSL(
0.55 + ratio * 0.055,
0.78,
0.44 + ratio * 0.12
);
const arrow = makeArrow(color);
arrow.position.set(-3.65, ratio * 1.4, z);
arrow.userData.ratio = ratio;
arrow.renderOrder = 4;
scene.add(arrow);
velocityArrows.push(arrow);
}
}
// White line connecting the arrow tips: the linear velocity profile.
const profilePositions = new Float32Array((rowRatios.length + 1) * 3);
const profileGeometry = new THREE.BufferGeometry();
profileGeometry.setAttribute(
"position",
new THREE.BufferAttribute(profilePositions, 3)
);
const profileLine = new THREE.Line(
profileGeometry,
new THREE.LineBasicMaterial({
color: 0xe8fcff,
transparent: true,
opacity: 0.64,
depthTest: false
})
);
profileLine.renderOrder = 12;
scene.add(profileLine);
const baselineGeometry = new THREE.BufferGeometry();
baselineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const profileBaseline = new THREE.Line(
baselineGeometry,
new THREE.LineDashedMaterial({
color: 0xa9d8e7,
transparent: true,
opacity: 0.35,
dashSize: 0.09,
gapSize: 0.07,
depthTest: false
})
);
profileBaseline.renderOrder = 11;
scene.add(profileBaseline);
// ------------------------------------------------------------------
// Low-poly fluid particles and short velocity trails
// ------------------------------------------------------------------
const particleGeometry = new THREE.IcosahedronGeometry(0.065, 0);
const particleMaterials = [
new THREE.MeshStandardMaterial({
color: 0x287cc1,
emissive: 0x103c66,
emissiveIntensity: 0.3,
roughness: 0.55,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x25aebc,
emissive: 0x0d4a52,
emissiveIntensity: 0.32,
roughness: 0.55,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x58e4d5,
emissive: 0x145c55,
emissiveIntensity: 0.32,
roughness: 0.55,
flatShading: true
})
];
const particles = [];
for (let i = 0; i < 76; i++) {
const ratio = 0.08 + Math.random() * 0.84;
const materialIndex = Math.min(
2,
Math.floor(ratio * 3)
);
const mesh = new THREE.Mesh(
particleGeometry,
particleMaterials[materialIndex]
);
mesh.position.set(
-4.15 + Math.random() * 8.3,
ratio * 1.4,
-1.82 + Math.random() * 3.64
);
mesh.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
scene.add(mesh);
const trailArray = new Float32Array(6);
const trailGeometry = new THREE.BufferGeometry();
trailGeometry.setAttribute(
"position",
new THREE.BufferAttribute(trailArray, 3)
);
const trail = new THREE.Line(
trailGeometry,
new THREE.LineBasicMaterial({
color: 0x6ce5e5,
transparent: true,
opacity: 0.23,
depthWrite: false
})
);
trail.renderOrder = 3;
scene.add(trail);
particles.push({
mesh,
trail,
trailArray,
ratio,
x: mesh.position.x,
z: mesh.position.z
});
}
// ------------------------------------------------------------------
// Drive and shear-resistance vectors
// ------------------------------------------------------------------
const driveArrow = makeArrow(0xffb15c);
driveArrow.position.set(-4.18, 1.95, -1.72);
scene.add(driveArrow);
const topResistance = makeArrow(0xff766d);
topResistance.rotation.y = Math.PI;
topResistance.position.set(3.75, 1.43, 2.27);
scene.add(topResistance);
const bottomResistance = makeArrow(0xff766d);
bottomResistance.position.set(-3.75, 0.055, 2.27);
scene.add(bottomResistance);
// Moving surface marks visually communicate the plate's drive direction.
const surfaceMarks = [];
const markGeometry = new THREE.BoxGeometry(0.045, 0.027, 3.85);
const markMaterial = new THREE.MeshStandardMaterial({
color: 0xffa64f,
emissive: 0x8a3c0b,
emissiveIntensity: 0.65,
roughness: 0.6,
metalness: 0.2
});
for (let i = 0; i < 7; i++) {
const mark = new THREE.Mesh(markGeometry, markMaterial);
mark.position.set(-3.9 + i * 1.3, 1.69, 0);
scene.add(mark);
surfaceMarks.push(mark);
}
// ------------------------------------------------------------------
// Scene labels
// ------------------------------------------------------------------
const topLabel = makeLabel("MOVING PLATE → U", "#ffb15c");
topLabel.position.set(-2.2, 2.36, 1.72);
scene.add(topLabel);
const fluidLabel = makeLabel("NEWTONIAN FLUID", "#56e7e0");
fluidLabel.position.set(2.65, 0.83, 2.32);
scene.add(fluidLabel);
const bottomLabel = makeLabel("FIXED PLATE", "#8daec4");
bottomLabel.position.set(-2.8, -0.55, 2.05);
scene.add(bottomLabel);
const profileLabel = makeLabel("LINEAR u(y)", "#e8fcff");
profileLabel.scale.multiplyScalar(0.72);
scene.add(profileLabel);
const resistanceLabel = makeLabel("SHEAR RESISTANCE", "#ff766d");
resistanceLabel.scale.multiplyScalar(0.72);
scene.add(resistanceLabel);
// ------------------------------------------------------------------
// State updates
// ------------------------------------------------------------------
function visualGap() {
return 1.25 + ((state.gapMm - 1) / 3) * 0.9;
}
function updateModel() {
state.U = Number(speedInput.value);
state.mu = Number(viscosityInput.value);
state.gapMm = Number(gapInput.value);
state.showForces = showForces.checked;
const gapMeters = state.gapMm / 1000;
const shearRate = state.U / gapMeters;
const shearStress = state.mu * shearRate;
const resistanceForce = shearStress * AREA;
const height = visualGap();
const maxProfileLength = 4.3 * (state.U / 2.5);
speedOut.textContent = `${state.U.toFixed(2)} m/s`;
viscosityOut.textContent = `${state.mu.toFixed(2)} Pa·s`;
gapOut.textContent = `${state.gapMm.toFixed(1)} mm`;
rateOut.textContent = `${shearRate.toFixed(0)} s⁻¹`;
stressOut.textContent = `${shearStress.toFixed(0)} Pa`;
forceOut.textContent = `${resistanceForce.toFixed(1)} N`;
topPlate.position.y = height + 0.14;
fluidBand.position.y = height * 0.5;
fluidBand.scale.y = height;
for (let i = 0; i < fluidLayers.length; i++) {
fluidLayers[i].position.y = ((i + 1) / 7) * height;
}
for (const arrow of velocityArrows) {
arrow.position.y = arrow.userData.ratio * height;
setArrowLength(
arrow,
maxProfileLength * arrow.userData.ratio
);
}
// Update the white velocity-profile line.
for (let i = 0; i <= rowRatios.length; i++) {
const ratio = i / rowRatios.length;
const offset = i * 3;
profilePositions[offset] =
-3.65 + maxProfileLength * ratio;
profilePositions[offset + 1] = ratio * height;
profilePositions[offset + 2] = 1.87;
}
profileGeometry.attributes.position.needsUpdate = true;
profileGeometry.computeBoundingSphere();
const base = profileBaseline.geometry.attributes.position;
base.setXYZ(0, -3.65, 0, 1.87);
base.setXYZ(1, -3.65, height, 1.87);
base.needsUpdate = true;
profileBaseline.computeLineDistances();
profileLabel.position.set(
-3.15 + maxProfileLength * 0.67,
height * 0.72,
1.9
);
// Applied drive.
driveArrow.position.y = height + 0.35;
setArrowLength(
driveArrow,
state.U > 0 ? 0.65 + state.U * 0.45 : 0
);
// Fluid shear on the upper plate points opposite the plate motion.
// Fluid shear on the lower plate points in the direction of flow.
const forceLength = Math.min(1.7, resistanceForce * 0.11);
topResistance.position.y = height - 0.065;
bottomResistance.position.y = 0.055;
setArrowLength(topResistance, forceLength);
setArrowLength(bottomResistance, forceLength * 0.82);
topResistance.visible =
state.showForces && forceLength > 0.015;
bottomResistance.visible =
state.showForces && forceLength > 0.015;
resistanceLabel.visible = state.showForces;
resistanceLabel.position.set(
1.35,
height + 0.48,
2.28
);
// Reposition particles when the gap changes.
for (const particle of particles) {
particle.mesh.position.y = particle.ratio * height;
particle.trailArray[1] = particle.mesh.position.y;
particle.trailArray[4] = particle.mesh.position.y;
}
topLabel.position.y = height + 0.79;
fluidLabel.position.y = height * 0.53;
}
[speedInput, viscosityInput, gapInput, showForces].forEach((control) => {
control.addEventListener("input", updateModel);
});
pauseButton.addEventListener("click", () => {
state.paused = !state.paused;
pauseButton.textContent = state.paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-pressed", String(state.paused));
});
updateModel();
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
let simulationTime = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
if (!state.paused) simulationTime += dt;
const height = visualGap();
// Low-poly tracer particles move at the local fluid velocity.
for (const particle of particles) {
const visualVelocity =
(0.12 + particle.ratio * 1.5) * (state.U / 1.4);
if (!state.paused) {
particle.x += visualVelocity * dt;
if (particle.x > 4.2) {
particle.x = -4.2;
}
particle.mesh.position.x = particle.x;
particle.mesh.rotation.x += dt * 0.35;
particle.mesh.rotation.y += dt * 0.22;
}
const trailLength = Math.min(0.65, visualVelocity * 0.24);
particle.trailArray[0] = particle.x - trailLength;
particle.trailArray[1] = particle.mesh.position.y;
particle.trailArray[2] = particle.z;
particle.trailArray[3] = particle.x;
particle.trailArray[4] = particle.mesh.position.y;
particle.trailArray[5] = particle.z;
particle.trail.geometry.attributes.position.needsUpdate = true;
}
// Surface marks travel in the plate-drive direction.
for (let i = 0; i < surfaceMarks.length; i++) {
const travel = state.paused
? 0
: simulationTime * state.U * 0.8;
const x = -3.95 + ((i * 1.3 + travel) % 7.9);
surfaceMarks[i].position.x = x;
surfaceMarks[i].position.y = height + 0.29;
}
driveArrow.userData.material.emissiveIntensity =
0.28 + Math.sin(simulationTime * 3.2) * 0.09;
updateCamera();
renderer.render(scene, camera);
}
animate();
loading.remove();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```