Prompt specification
Build or customize the Three.js 3D scene "Primed siphon tube between tanks" 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: Primed siphon tube between tanks
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/primed-siphon-tube-between-tanks-x1497
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a siphon connecting two reservoirs. Build two reservoirs at different surface elevations joined by a fully filled arched tube; show the outlet below the source surface and label the primed condition. Low-poly.
Working Three.js Starter (primed-siphon-tube-between-tanks-x1497):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Primed Siphon — Low-Poly Three.js Scene</title>
<style>
:root {
color-scheme: light;
--ink: #17343c;
--muted: #61777b;
--panel: rgba(250, 253, 249, 0.88);
--line: rgba(23, 52, 60, 0.14);
--accent: #0d9bc3;
--green: #16865c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
min-width: 132px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 9px;
background: rgba(248, 252, 248, 0.88);
box-shadow:
0 8px 24px rgba(31, 61, 66, 0.12),
0 1px 2px rgba(31, 61, 66, 0.08);
backdrop-filter: blur(8px);
transform: translate(-50%, -50%);
white-space: nowrap;
line-height: 1.15;
}
.scene-label small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
font-size: 13px;
font-weight: 750;
}
.scene-label em {
display: block;
margin-top: 4px;
color: #a35f20;
font-size: 10px;
font-style: normal;
font-weight: 700;
}
.scene-label.primed {
border-color: rgba(22, 134, 92, 0.35);
background: rgba(236, 251, 241, 0.94);
}
.scene-label.primed strong {
color: var(--green);
letter-spacing: 0.08em;
}
.pulse {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 50%;
background: #20b879;
box-shadow: 0 0 0 4px rgba(32, 184, 121, 0.14);
vertical-align: 1px;
}
.measure-label {
min-width: auto;
padding: 6px 9px;
border-radius: 7px;
background: rgba(255, 248, 235, 0.92);
color: #9b5b1d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
#hud {
position: fixed;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 18px 19px 16px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 16px 44px rgba(34, 62, 65, 0.14);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 4px;
font-size: clamp(25px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 8px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.status {
display: flex;
align-items: center;
gap: 9px;
padding: 9px 10px;
border: 1px solid rgba(22, 134, 92, 0.22);
border-radius: 9px;
background: rgba(222, 246, 231, 0.7);
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status .pulse {
flex: 0 0 auto;
margin: 0;
}
.readout {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 13px;
}
.readout div {
padding-top: 9px;
border-top: 1px solid var(--line);
}
.readout span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
}
.readout strong {
font-size: 13px;
}
#help {
position: fixed;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 20px;
background: rgba(248, 252, 248, 0.76);
color: var(--muted);
font-size: 10px;
font-weight: 650;
backdrop-filter: blur(8px);
pointer-events: none;
}
@media (max-width: 650px) {
#hud {
top: 12px;
left: 12px;
width: min(290px, calc(100vw - 24px));
padding: 14px;
}
.subtitle,
.readout {
display: none;
}
.scene-label {
min-width: 108px;
padding: 7px 9px;
}
.scene-label strong {
font-size: 11px;
}
#help {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels" aria-hidden="true">
<div id="label-source" class="scene-label">
<small>Upper reservoir</small>
<strong>Surface 2.12 m</strong>
</div>
<div id="label-primed" class="scene-label primed">
<small>Operating state</small>
<strong><span class="pulse"></span>PRIMED</strong>
<small>Tube 100% full · no air</small>
</div>
<div id="label-outlet" class="scene-label">
<small>Discharge outlet</small>
<strong>Outlet 0.96 m</strong>
<em>1.16 m below source surface</em>
</div>
<div id="label-lower" class="scene-label">
<small>Lower reservoir</small>
<strong>Surface 0.70 m</strong>
</div>
<div id="label-inlet" class="scene-label">
<small>Inlet</small>
<strong>Submerged</strong>
</div>
<div id="label-drop" class="scene-label measure-label">
1.16 m DROP
</div>
</div>
<header id="hud">
<div class="eyebrow">Fluid systems / 01</div>
<h1>Primed Siphon</h1>
<p class="subtitle">
Two reservoirs at different elevations, joined by one continuous,
fully filled arched tube.
</p>
<div class="status">
<span class="pulse"></span>
Primed · continuous liquid column
</div>
<div class="readout">
<div>
<span>Source</span>
<strong>2.12 m</strong>
</div>
<div>
<span>Outlet</span>
<strong>0.96 m</strong>
</div>
<div>
<span>Head</span>
<strong>1.16 m</strong>
</div>
</div>
</header>
<div id="help">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly scene showing a primed siphon between two reservoirs"
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e4);
scene.fog = new THREE.Fog(0xdce8e4, 19, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
camera.position.set(10.2, 7.1, 13.4);
const controlsTarget = new THREE.Vector3(0, 1.35, 0);
camera.lookAt(controlsTarget);
scene.add(new THREE.HemisphereLight(0xf6fffb, 0x748477, 2.15));
const sun = new THREE.DirectionalLight(0xfff8e8, 3.2);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x9bdcf0, 1.1);
rimLight.position.set(9, 6, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const materials = {
concrete: new THREE.MeshStandardMaterial({
color: 0xd9d3c2,
roughness: 0.94,
flatShading: true
}),
rim: new THREE.MeshStandardMaterial({
color: 0xb9b09c,
roughness: 0.86,
flatShading: true
}),
foundation: new THREE.MeshStandardMaterial({
color: 0xa9a79a,
roughness: 0.96,
flatShading: true
}),
base: new THREE.MeshStandardMaterial({
color: 0x9ca69b,
roughness: 0.96,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x526970,
roughness: 0.55,
metalness: 0.45,
flatShading: true
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x273d43,
roughness: 0.65,
metalness: 0.35,
flatShading: true
}),
waterVolume: new THREE.MeshPhongMaterial({
color: 0x39a9d1,
transparent: true,
opacity: 0.28,
shininess: 85,
depthWrite: false,
side: THREE.DoubleSide
}),
waterLine: new THREE.MeshBasicMaterial({
color: 0x168fbd,
transparent: true,
opacity: 0.82
}),
pipeShell: new THREE.MeshPhongMaterial({
color: 0xd8f8ff,
transparent: true,
opacity: 0.32,
shininess: 120,
specular: 0xffffff,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
}),
pipeWater: new THREE.MeshPhongMaterial({
color: 0x16a8dd,
emissive: 0x073b50,
emissiveIntensity: 0.6,
transparent: true,
opacity: 0.82,
shininess: 80,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
}),
flowMarker: new THREE.MeshBasicMaterial({
color: 0xd9fbff,
transparent: true,
opacity: 0.9,
depthWrite: false
})
};
function box(parent, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeDashedLine(points, color = 0xb67936, opacity = 0.52) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.11,
gapSize: 0.075,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
return line;
}
let seed = 173;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// -------------------------------------------------------------------------
// Low-poly ground and scenery
// -------------------------------------------------------------------------
box(scene, 24, 0.46, 12, materials.base, 0, -0.38, 0);
const terrainGeometry = new THREE.PlaneGeometry(23.5, 11.5, 14, 8);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPositions = terrainGeometry.attributes.position;
const terrainColors = [];
for (let i = 0; i < terrainPositions.count; i++) {
terrainPositions.setY(
i,
-0.105 + (random() - 0.5) * 0.075
);
const color = new THREE.Color().setHSL(
0.27 + random() * 0.035,
0.17,
0.65 + random() * 0.065
);
terrainColors.push(color.r, color.g, color.b);
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x8e9b8d,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 16; i++) {
const x = -10.7 + random() * 21.4;
const z = -4.8 + random() * 9.6;
if (z > -1.65 && z < 1.65 && x > -6.2 && x < 6.2) {
continue;
}
const scale = 0.18 + random() * 0.38;
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.set(x, -0.04 + scale * 0.48, z);
rock.scale.set(
scale * (0.8 + random() * 0.5),
scale * (0.55 + random() * 0.45),
scale * (0.75 + random() * 0.55)
);
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x665441,
roughness: 1,
flatShading: true
});
const foliageMaterial = new THREE.MeshStandardMaterial({
color: 0x416f58,
roughness: 1,
flatShading: true
});
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, -0.08, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.1, 0.72, 6),
trunkMaterial
);
trunk.position.y = 0.36;
trunk.castShadow = true;
tree.add(trunk);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.12, 7),
foliageMaterial
);
lower.position.y = 0.95;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.34, 0.9, 7),
foliageMaterial
);
upper.position.y = 1.48;
upper.castShadow = true;
tree.add(upper);
scene.add(tree);
}
[
[-9.5, -4.7, 1.05],
[-7.4, -4.9, 0.8],
[-4.9, -4.7, 0.9],
[6.2, -4.8, 0.95],
[8.5, -4.5, 1.12],
[10.1, -3.7, 0.82]
].forEach((data) => addTree(...data));
// -------------------------------------------------------------------------
// Reservoirs
// -------------------------------------------------------------------------
const waterSurfaces = [];
function createReservoir({
centerX,
bottomY,
width,
depth,
wallHeight,
waterLevel
}) {
const group = new THREE.Group();
const thickness = 0.22;
// Bottom slab.
box(
group,
width + thickness * 2,
0.22,
depth + thickness * 2,
materials.concrete,
centerX,
bottomY - 0.11,
0
);
// Side walls.
box(
group,
thickness,
wallHeight,
depth + thickness * 2,
materials.concrete,
centerX - width / 2 - thickness / 2,
bottomY + wallHeight / 2,
0
);
box(
group,
thickness,
wallHeight,
depth + thickness * 2,
materials.concrete,
centerX + width / 2 + thickness / 2,
bottomY + wallHeight / 2,
0
);
// Front and rear walls.
box(
group,
width,
wallHeight,
thickness,
materials.concrete,
centerX,
bottomY + wallHeight / 2,
-depth / 2 - thickness / 2
);
box(
group,
width,
wallHeight,
thickness,
materials.concrete,
centerX,
bottomY + wallHeight / 2,
depth / 2 + thickness / 2
);
// Slightly darker top rims.
const rimY = bottomY + wallHeight + 0.035;
box(
group,
thickness + 0.05,
0.07,
depth + thickness * 2 + 0.05,
materials.rim,
centerX - width / 2 - thickness / 2,
rimY,
0
);
box(
group,
thickness + 0.05,
0.07,
depth + thickness * 2 + 0.05,
materials.rim,
centerX + width / 2 + thickness / 2,
rimY,
0
);
box(
group,
width + 0.05,
0.07,
thickness + 0.05,
materials.rim,
centerX,
rimY,
-depth / 2 - thickness / 2
);
box(
group,
width + 0.05,
0.07,
thickness + 0.05,
materials.rim,
centerX,
rimY,
depth / 2 + thickness / 2
);
// Visible body of water.
const waterHeight = waterLevel - bottomY;
const waterVolume = new THREE.Mesh(
new THREE.BoxGeometry(width - 0.035, waterHeight, depth - 0.035),
materials.waterVolume
);
waterVolume.position.set(
centerX,
bottomY + waterHeight / 2,
0
);
waterVolume.renderOrder = 1;
group.add(waterVolume);
// Faceted, animated surface.
const surfaceGeometry = new THREE.PlaneGeometry(
width - 0.035,
depth - 0.035,
10,
8
);
surfaceGeometry.rotateX(-Math.PI / 2);
const surfaceMaterial = new THREE.MeshStandardMaterial({
color: 0x36b2dc,
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
flatShading: true
});
const surface = new THREE.Mesh(surfaceGeometry, surfaceMaterial);
surface.position.set(centerX, waterLevel, 0);
surface.receiveShadow = true;
surface.renderOrder = 2;
group.add(surface);
waterSurfaces.push({ mesh: surface, level: waterLevel });
// Thin waterline strips along the inside walls.
box(
group,
width,
0.035,
0.028,
materials.waterLine,
centerX,
waterLevel,
-depth / 2 + 0.015
);
box(
group,
width,
0.035,
0.028,
materials.waterLine,
centerX,
waterLevel,
depth / 2 - 0.015
);
box(
group,
0.028,
0.035,
depth,
materials.waterLine,
centerX - width / 2 + 0.015,
waterLevel,
0
);
box(
group,
0.028,
0.035,
depth,
materials.waterLine,
centerX + width / 2 - 0.015,
waterLevel,
0
);
scene.add(group);
return group;
}
// Distinct plinths reinforce the source's higher elevation.
box(scene, 4.05, 0.56, 3.15, materials.foundation, -3.8, 0.22, 0);
box(scene, 3.9, 0.18, 3.05, materials.foundation, 3.7, -0.04, 0);
createReservoir({
centerX: -3.8,
bottomY: 0.62,
width: 3.2,
depth: 2.4,
wallHeight: 2.16,
waterLevel: 2.12
});
createReservoir({
centerX: 3.7,
bottomY: 0.15,
width: 3.2,
depth: 2.4,
wallHeight: 1.1,
waterLevel: 0.7
});
// -------------------------------------------------------------------------
// Fully filled arched siphon
// -------------------------------------------------------------------------
const siphonPoints = [
new THREE.Vector3(-4.55, 1.47, 0),
new THREE.Vector3(-4.18, 1.47, 0),
new THREE.Vector3(-3.45, 1.47, 0),
new THREE.Vector3(-2.68, 1.49, 0),
new THREE.Vector3(-2.08, 1.65, 0),
new THREE.Vector3(-1.52, 2.55, 0),
new THREE.Vector3(-1.05, 3.52, 0),
new THREE.Vector3(-0.2, 3.82, 0),
new THREE.Vector3(0.72, 3.72, 0),
new THREE.Vector3(1.42, 3.12, 0),
new THREE.Vector3(1.82, 2.22, 0),
new THREE.Vector3(2.08, 1.48, 0),
new THREE.Vector3(2.48, 1.02, 0),
new THREE.Vector3(2.95, 0.96, 0)
];
const siphonCurve = new THREE.CatmullRomCurve3(
siphonPoints,
false,
"catmullrom",
0.16
);
// Transparent outer tube.
const shell = new THREE.Mesh(
new THREE.TubeGeometry(siphonCurve, 76, 0.19, 10, false),
materials.pipeShell
);
shell.renderOrder = 4;
scene.add(shell);
// Continuous blue liquid core: this is what makes the tube fully primed.
const liquidCore = new THREE.Mesh(
new THREE.TubeGeometry(siphonCurve, 76, 0.135, 8, false),
materials.pipeWater
);
liquidCore.renderOrder = 2;
scene.add(liquidCore);
// Filled cross-sections at both ends.
const crossSectionGeometry = new THREE.CircleGeometry(0.135, 10);
const normal = new THREE.Vector3(0, 0, 1);
[0, 1].forEach((end) => {
const cap = new THREE.Mesh(crossSectionGeometry, materials.pipeWater);
cap.position.copy(siphonCurve.getPointAt(end));
cap.quaternion.setFromUnitVectors(
normal,
siphonCurve.getTangentAt(end).normalize()
);
cap.renderOrder = 3;
scene.add(cap);
});
// Source-wall flange.
const sourceFlange = new THREE.Mesh(
new THREE.TorusGeometry(0.225, 0.052, 6, 12),
materials.metal
);
sourceFlange.position.set(-2.07, 1.65, 0);
sourceFlange.rotation.y = Math.PI / 2;
sourceFlange.castShadow = true;
scene.add(sourceFlange);
// Outlet flange and short nozzle.
const outletFlange = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.05, 6, 12),
materials.metal
);
outletFlange.position.set(2.9, 0.96, 0);
outletFlange.rotation.y = Math.PI / 2;
outletFlange.castShadow = true;
scene.add(outletFlange);
const nozzle = new THREE.Mesh(
new THREE.CylinderGeometry(0.205, 0.205, 0.24, 10, 1, true),
materials.metal
);
nozzle.position.set(2.94, 0.96, 0);
nozzle.rotation.z = Math.PI / 2;
nozzle.castShadow = true;
scene.add(nozzle);
// Submerged intake strainer.
const strainer = new THREE.Group();
strainer.position.set(-4.55, 0, 0);
const strainerBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.21, 0.21, 0.45, 8, 1, true),
materials.darkMetal
);
strainerBody.position.y = 1.245;
strainerBody.castShadow = true;
strainer.add(strainerBody);
[1.02, 1.47].forEach((y) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.215, 0.025, 5, 10),
materials.metal
);
ring.position.y = y;
ring.rotation.x = Math.PI / 2;
strainer.add(ring);
});
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const slat = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.38, 0.04),
materials.metal
);
slat.position.set(
Math.sin(angle) * 0.205,
1.245,
Math.cos(angle) * 0.205
);
slat.rotation.y = angle;
strainer.add(slat);
}
scene.add(strainer);
// Outlet stream falling into the lower reservoir.
const streamCurve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(2.95, 0.95, 0),
new THREE.Vector3(2.98, 0.79, 0),
new THREE.Vector3(3.08, 0.695, 0)
);
const streamMaterial = new THREE.MeshPhongMaterial({
color: 0x29b9e4,
emissive: 0x06384b,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.85,
shininess: 80,
depthWrite: false,
flatShading: true
});
const stream = new THREE.Mesh(
new THREE.TubeGeometry(streamCurve, 18, 0.055, 7, false),
streamMaterial
);
stream.renderOrder = 3;
scene.add(stream);
const splash = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.014, 5, 16),
new THREE.MeshBasicMaterial({
color: 0xb9f4ff,
transparent: true,
opacity: 0.75,
depthWrite: false
})
);
splash.position.set(3.08, 0.716, 0);
splash.rotation.x = Math.PI / 2;
scene.add(splash);
// -------------------------------------------------------------------------
// Elevation reference: outlet is visibly below the source surface
// -------------------------------------------------------------------------
makeDashedLine([
[-2.35, 2.12, 0.08],
[3.55, 2.12, 0.08]
]);
makeDashedLine([
[2.95, 0.96, 0.08],
[3.55, 0.96, 0.08]
]);
makeDashedLine([
[3.55, 0.96, 0.08],
[3.55, 2.12, 0.08]
]);
makeDashedLine([
[3.42, 0.96, 0.08],
[3.68, 0.96, 0.08]
]);
makeDashedLine([
[3.42, 2.12, 0.08],
[3.68, 2.12, 0.08]
]);
// -------------------------------------------------------------------------
// Flow markers inside the already-full tube
// -------------------------------------------------------------------------
const flowMarkers = [];
const flowMarkerGeometry = new THREE.IcosahedronGeometry(0.038, 0);
for (let i = 0; i < 15; i++) {
const marker = new THREE.Mesh(
flowMarkerGeometry,
materials.flowMarker
);
marker.renderOrder = 3;
scene.add(marker);
flowMarkers.push(marker);
}
// -------------------------------------------------------------------------
// Screen-space labels anchored to the 3D scene
// -------------------------------------------------------------------------
const labelDefinitions = [
{
id: "label-source",
position: new THREE.Vector3(-3.8, 2.18, 0),
offset: new THREE.Vector2(-8, -23)
},
{
id: "label-primed",
position: new THREE.Vector3(0, 3.92, 0),
offset: new THREE.Vector2(0, -27)
},
{
id: "label-outlet",
position: new THREE.Vector3(2.98, 0.96, 0),
offset: new THREE.Vector2(68, 29)
},
{
id: "label-lower",
position: new THREE.Vector3(3.7, 0.76, 0),
offset: new THREE.Vector2(17, 21)
},
{
id: "label-inlet",
position: new THREE.Vector3(-4.55, 1.18, 0),
offset: new THREE.Vector2(-61, 12)
},
{
id: "label-drop",
position: new THREE.Vector3(3.55, 1.54, 0.08),
offset: new THREE.Vector2(48, 0)
}
];
labelDefinitions.forEach((definition) => {
definition.element = document.getElementById(definition.id);
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = host.clientWidth;
const height = host.clientHeight;
labelDefinitions.forEach((definition) => {
projected.copy(definition.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
definition.element.style.visibility = visible ? "visible" : "hidden";
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
definition.element.style.transform =
`translate(-50%, -50%) ` +
`translate(${definition.offset.x}px, ${definition.offset.y}px)`;
});
}
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
const spherical = new THREE.Spherical().setFromVector3(
camera.position.clone().sub(controlsTarget)
);
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.35,
1.43
);
camera.position
.setFromSpherical(spherical)
.add(controlsTarget);
camera.lookAt(controlsTarget);
});
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(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
9,
27
);
camera.position
.setFromSpherical(spherical)
.add(controlsTarget);
camera.lookAt(controlsTarget);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 650 ? 48 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Gentle low-poly water motion.
waterSurfaces.forEach(({ mesh }, index) => {
const positions = mesh.geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const z = positions.getZ(i);
const wave =
Math.sin(x * 2.3 + elapsed * 1.25 + index) * 0.012 +
Math.cos(z * 3.1 - elapsed * 1.05) * 0.008;
positions.setY(i, wave);
}
positions.needsUpdate = true;
mesh.geometry.computeVertexNormals();
});
// Moving highlights imply flow through the continuous primed liquid core.
flowMarkers.forEach((marker, index) => {
const u = (index / flowMarkers.length + elapsed * 0.105) % 1;
marker.position.copy(siphonCurve.getPointAt(u));
});
// Pulsing splash at the lower reservoir.
const splashScale = 1 + Math.sin(elapsed * 4.8) * 0.22;
splash.scale.set(splashScale, splashScale, splashScale);
splash.material.opacity = 0.58 + Math.sin(elapsed * 4.8) * 0.15;
streamMaterial.opacity = 0.78 + Math.sin(elapsed * 5.2) * 0.07;
renderer.render(scene, camera);
updateLabels();
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```