Prompt specification
Build or customize the Three.js 3D scene "Straight dye filament in a pipe" 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: Straight dye filament in a pipe
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/straight-dye-filament-in-a-pipe-x1465
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build a transparent pipe with a thin colored tracer line following a smooth flow; label the pattern an illustrative laminar-flow example rather than a solved fluid field.
Working Three.js Starter (straight-dye-filament-in-a-pipe-x1465):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Illustrative Laminar Flow</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 28%, #17374a 0%, #0a1b28 42%, #050d16 100%);
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background: radial-gradient(
ellipse at center,
transparent 45%,
rgba(0, 0, 0, 0.38) 100%
);
z-index: 2;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 3;
pointer-events: none;
color: #eaf8ff;
}
.title-card {
top: clamp(20px, 4vw, 48px);
left: clamp(20px, 4vw, 52px);
width: min(470px, calc(100vw - 40px));
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 15px;
padding: 7px 10px;
border: 1px solid rgba(136, 220, 237, 0.25);
border-radius: 999px;
background: rgba(8, 25, 37, 0.58);
color: #93dbe8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.eyebrow::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #ff705b;
box-shadow: 0 0 12px rgba(255, 112, 91, 0.8);
}
h1 {
margin: 0;
max-width: 440px;
font-size: clamp(30px, 4.6vw, 58px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
text-shadow: 0 3px 24px rgba(0, 0, 0, 0.35);
}
.description {
max-width: 410px;
margin: 18px 0 0;
color: rgba(220, 241, 249, 0.72);
font-size: clamp(13px, 1.35vw, 16px);
line-height: 1.55;
}
.disclaimer {
display: inline-block;
margin-top: 13px;
padding: 8px 11px;
border-left: 2px solid #ff705b;
background: linear-gradient(
90deg,
rgba(255, 112, 91, 0.13),
rgba(255, 112, 91, 0)
);
color: #ffb2a7;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.flow-pill {
top: clamp(20px, 4vw, 48px);
right: clamp(20px, 4vw, 52px);
display: flex;
align-items: center;
gap: 11px;
padding: 10px 13px;
border: 1px solid rgba(129, 213, 232, 0.2);
border-radius: 10px;
background: rgba(7, 23, 34, 0.56);
color: #9ddce8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
backdrop-filter: blur(10px);
}
.flow-arrow {
color: #ff765f;
font-size: 19px;
line-height: 0;
text-shadow: 0 0 14px rgba(255, 118, 95, 0.45);
}
.legend {
bottom: clamp(20px, 4vw, 44px);
left: clamp(20px, 4vw, 52px);
display: flex;
flex-wrap: wrap;
gap: 18px;
color: rgba(221, 241, 247, 0.7);
font-size: 11px;
letter-spacing: 0.04em;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 22px;
height: 3px;
border-radius: 3px;
}
.swatch.tracer {
background: #ff684f;
box-shadow: 0 0 9px rgba(255, 104, 79, 0.55);
}
.swatch.pipe {
height: 9px;
border: 1px solid rgba(153, 226, 238, 0.8);
background: rgba(153, 226, 238, 0.14);
}
.hint {
right: clamp(20px, 4vw, 52px);
bottom: clamp(20px, 4vw, 44px);
color: rgba(205, 230, 239, 0.45);
font-size: 10px;
letter-spacing: 0.06em;
text-align: right;
}
@media (max-width: 700px) {
.title-card {
width: calc(100vw - 40px);
}
.description {
max-width: 320px;
}
.flow-pill {
top: auto;
right: 20px;
bottom: 68px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly pipe with an illustrative tracer"></canvas>
<div class="hud title-card">
<div class="eyebrow">Illustrative pattern</div>
<h1>Illustrative laminar-flow example</h1>
<p class="description">
A thin tracer follows a smooth, deliberately ordered path through a
transparent low-poly pipe.
</p>
<div class="disclaimer">Not a solved fluid field</div>
</div>
<div class="hud flow-pill">
FLOW DIRECTION <span class="flow-arrow">→</span>
</div>
<div class="hud legend">
<span class="legend-item">
<span class="swatch tracer"></span>
Colored tracer
</span>
<span class="legend-item">
<span class="swatch pipe"></span>
Transparent pipe
</span>
</div>
<div class="hud hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom<br />
Double-click to reset view
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x071521, 13, 27);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemisphere = new THREE.HemisphereLight(0xbceeff, 0x07121b, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe7f8ff, 3.4);
keyLight.position.set(3, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x53cfe8, 2.3);
rimLight.position.set(-6, 3, -5);
scene.add(rimLight);
const tracerLight = new THREE.PointLight(0xff654c, 5, 7, 2);
tracerLight.position.set(-2.5, 2.25, 0.8);
scene.add(tracerLight);
// Ground and restrained technical grid.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(34, 34),
new THREE.MeshStandardMaterial({
color: 0x07131c,
roughness: 0.96,
metalness: 0.04
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x285467, 0x15313e);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
const pipeCenterY = 2.05;
const pipeRadius = 1.05;
const pipeLength = 9.4;
const structureMaterial = new THREE.MeshStandardMaterial({
color: 0x163747,
roughness: 0.55,
metalness: 0.55,
flatShading: true
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x102b38,
roughness: 0.7,
metalness: 0.35,
flatShading: true
});
// Two low-poly support assemblies.
for (const x of [-2.7, 2.7]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.43, 1.22, 6),
supportMaterial
);
post.position.set(x, 0.68, 0);
post.castShadow = true;
post.receiveShadow = true;
scene.add(post);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.36, 0.36, 0.18, 6),
structureMaterial
);
collar.position.set(x, 1.23, 0);
collar.castShadow = true;
scene.add(collar);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.16, 1.15),
structureMaterial
);
foot.position.set(x, 0.08, 0);
foot.castShadow = true;
foot.receiveShadow = true;
scene.add(foot);
const saddle = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.25, 1.72),
supportMaterial
);
saddle.position.set(x, 1.38, 0);
saddle.castShadow = true;
scene.add(saddle);
}
// Faceted transparent pipe shell.
const pipeGeometry = new THREE.CylinderGeometry(
pipeRadius,
pipeRadius,
pipeLength,
12,
1,
true
);
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xa9edf3,
roughness: 0.16,
metalness: 0.02,
transparent: true,
opacity: 0.19,
side: THREE.DoubleSide,
depthWrite: false,
clearcoat: 0.85,
clearcoatRoughness: 0.2
});
const pipe = new THREE.Mesh(pipeGeometry, glassMaterial);
pipe.rotation.z = Math.PI / 2;
pipe.position.y = pipeCenterY;
pipe.renderOrder = 5;
scene.add(pipe);
// Fine edges make the intentionally low-poly shell easy to read.
const pipeEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(pipeGeometry, 1),
new THREE.LineBasicMaterial({
color: 0xbceef4,
transparent: true,
opacity: 0.24
})
);
pipeEdges.rotation.copy(pipe.rotation);
pipeEdges.position.copy(pipe.position);
pipeEdges.renderOrder = 6;
scene.add(pipeEdges);
// Low-poly end collars and bolts.
const collarMaterial = new THREE.MeshStandardMaterial({
color: 0x1a4859,
roughness: 0.38,
metalness: 0.7,
flatShading: true
});
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0x87bdc9,
roughness: 0.3,
metalness: 0.85,
flatShading: true
});
for (const x of [-pipeLength / 2, pipeLength / 2]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.08, 0.095, 6, 16),
collarMaterial
);
ring.rotation.y = Math.PI / 2;
ring.position.set(x, pipeCenterY, 0);
ring.castShadow = true;
scene.add(ring);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 0.12, 6),
boltMaterial
);
bolt.rotation.z = Math.PI / 2;
bolt.position.set(
x,
pipeCenterY + Math.cos(angle) * 1.08,
Math.sin(angle) * 1.08
);
bolt.castShadow = true;
scene.add(bolt);
}
}
// The tracer is a visual guide, not a numerical fluid solution.
const tracerCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-4.8, pipeCenterY + 0.02, 0.02),
new THREE.Vector3(-3.6, pipeCenterY + 0.11, 0.24),
new THREE.Vector3(-2.2, pipeCenterY - 0.10, -0.22),
new THREE.Vector3(-0.8, pipeCenterY + 0.14, 0.19),
new THREE.Vector3(0.7, pipeCenterY - 0.09, -0.18),
new THREE.Vector3(2.1, pipeCenterY + 0.12, 0.16),
new THREE.Vector3(3.4, pipeCenterY - 0.06, -0.12),
new THREE.Vector3(4.8, pipeCenterY + 0.03, 0.04)
],
false,
"centripetal"
);
const tracerGlow = new THREE.Mesh(
new THREE.TubeGeometry(tracerCurve, 96, 0.072, 6, false),
new THREE.MeshBasicMaterial({
color: 0xff684f,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
tracerGlow.renderOrder = 3;
scene.add(tracerGlow);
const tracerMaterial = new THREE.MeshStandardMaterial({
color: 0xff684f,
emissive: 0xff3e29,
emissiveIntensity: 1.15,
roughness: 0.38,
metalness: 0.08
});
const tracer = new THREE.Mesh(
new THREE.TubeGeometry(tracerCurve, 96, 0.025, 6, false),
tracerMaterial
);
tracer.renderOrder = 4;
scene.add(tracer);
// Small moving highlights communicate direction along the tracer.
const pulseGeometry = new THREE.IcosahedronGeometry(0.058, 0);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xffd071
});
const pulses = [];
const pulseCount = 8;
for (let i = 0; i < pulseCount; i++) {
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
pulse.renderOrder = 7;
scene.add(pulse);
pulses.push(pulse);
}
// Small inlet/outlet direction markers.
const flowMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x6ab5c4,
emissive: 0x194f5c,
emissiveIntensity: 0.45,
roughness: 0.42,
metalness: 0.45,
flatShading: true
});
const inletArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.48, 5),
flowMarkerMaterial
);
inletArrow.rotation.z = -Math.PI / 2;
inletArrow.position.set(-5.35, pipeCenterY, 0);
scene.add(inletArrow);
const outletArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.48, 5),
flowMarkerMaterial
);
outletArrow.rotation.z = -Math.PI / 2;
outletArrow.position.set(5.35, pipeCenterY, 0);
scene.add(outletArrow);
// Custom camera controls: no examples/addons are imported.
const initialTarget = new THREE.Vector3(0, 1.45, 0);
const target = initialTarget.clone();
let radius = window.innerWidth < 700 ? 14.6 : 12.3;
let theta = 0.52;
let phi = 1.08;
let dragging = false;
let dragMode = "orbit";
let previousX = 0;
let previousY = 0;
function updateCamera() {
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);
camera.updateMatrixWorld();
}
function resetCamera() {
target.copy(initialTarget);
radius = window.innerWidth < 700 ? 14.6 : 12.3;
theta = 0.52;
phi = 1.08;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragMode === "orbit") {
theta -= dx * 0.005;
phi = THREE.MathUtils.clamp(phi - dy * 0.004, 0.42, 1.48);
} else {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
target.addScaledVector(right, -dx * radius * 0.0014);
target.addScaledVector(forward, dy * radius * 0.0014);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
8.5,
20
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "r" || event.key === "R") 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);
const clock = new THREE.Clock();
const pulsePosition = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
pulses.forEach((pulse, index) => {
const u = (elapsed * 0.13 + index / pulseCount) % 1;
tracerCurve.getPoint(u, pulsePosition);
pulse.position.copy(pulsePosition);
pulse.rotation.x = elapsed * 1.2 + index;
pulse.rotation.y = elapsed * 0.8 + index;
pulse.scale.setScalar(0.84 + Math.sin(elapsed * 5 + index) * 0.16);
});
tracerMaterial.emissiveIntensity =
1.05 + Math.sin(elapsed * 2.1) * 0.12;
tracerLight.intensity =
4.6 + Math.sin(elapsed * 2.1) * 0.7;
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resetCamera();
animate();
</script>
</body>
</html>
```