Prompt specification
Build or customize the Three.js 3D scene "Different-shaped vessels equal-depth comparison" 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: Different-shaped vessels equal-depth comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/different-shaped-vessels-equal-depth-comparison-x1486
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts hydrostatic pressure at different depths. Place three differently shaped containers filled to the same surface height; show equal pressure at equal depth despite different total water volumes. Stylized solid forms.
Working Three.js Starter (different-shaped-vessels-equal-depth-comparison-x1486):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hydrostatic Pressure — Equal Depth, Equal Pressure</title>
<style>
:root {
--bg: #07111e;
--panel: rgba(12, 27, 43, 0.78);
--panel-border: rgba(168, 216, 255, 0.15);
--text: #edf8ff;
--muted: #91a9bc;
--cyan: #54dff1;
--coral: #ff806d;
--gold: #ffc46b;
}
* {
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;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
user-select: none;
}
.hero {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(430px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.hero p {
margin: 12px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.equation {
display: inline-flex;
flex-wrap: wrap;
align-items: center;
gap: 7px;
padding: 9px 12px;
border: 1px solid rgba(84, 223, 241, 0.2);
border-radius: 10px;
background: rgba(84, 223, 241, 0.07);
color: #c9f7ff;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.equation strong {
color: var(--cyan);
font-weight: 800;
}
.legend {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
width: 220px;
padding: 15px 17px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
}
.legend-title {
margin-bottom: 10px;
color: #bed0de;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: #aebfcd;
font-size: 11px;
}
.swatch {
width: 22px;
height: 8px;
border-radius: 10px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(84, 223, 241, 0.5);
}
.swatch.ring {
width: 14px;
height: 14px;
border: 3px solid var(--coral);
border-radius: 50%;
background: transparent;
box-shadow: 0 0 12px rgba(255, 128, 109, 0.35);
}
.swatch.dash {
height: 0;
border-top: 2px dashed #a5d8ef;
border-radius: 0;
background: transparent;
box-shadow: none;
}
.controls {
position: fixed;
z-index: 5;
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 18px;
width: min(690px, calc(100vw - 32px));
padding: 14px 16px;
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(16px);
}
.depth-control {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 12px;
flex: 1;
min-width: 0;
}
.depth-control label {
color: #dcebf5;
font-size: 12px;
font-weight: 700;
}
#depth {
width: 100%;
accent-color: var(--coral);
cursor: pointer;
}
#depth-value {
min-width: 61px;
padding: 5px 8px;
border-radius: 8px;
background: rgba(255, 128, 109, 0.1);
color: #ffad9f;
font-size: 12px;
font-weight: 800;
text-align: center;
font-variant-numeric: tabular-nums;
}
.divider {
width: 1px;
height: 35px;
background: var(--panel-border);
}
#reset {
padding: 9px 12px;
border: 1px solid rgba(168, 216, 255, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #dcebf5;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
#reset:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(168, 216, 255, 0.35);
}
.hint {
position: fixed;
right: 24px;
bottom: 28px;
z-index: 4;
color: rgba(190, 211, 226, 0.62);
font-size: 10px;
letter-spacing: 0.05em;
pointer-events: none;
}
.vessel-label {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 11px;
border: 1px solid rgba(185, 221, 245, 0.13);
border-radius: 11px;
background: rgba(8, 22, 35, 0.78);
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(9px);
}
.vessel-index {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 7px;
background: rgba(255, 255, 255, 0.07);
color: var(--accent);
font-size: 10px;
font-weight: 900;
}
.vessel-label b {
display: block;
color: #edf8ff;
font-size: 11px;
letter-spacing: 0.01em;
}
.vessel-label small {
display: block;
margin-top: 2px;
color: #8fa8ba;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.pressure-label {
padding: 5px 9px;
border: 1px solid rgba(255, 128, 109, 0.55);
border-radius: 999px;
background: rgba(72, 27, 29, 0.84);
color: #ffb2a6;
font-size: 11px;
font-weight: 900;
font-variant-numeric: tabular-nums;
box-shadow: 0 0 18px rgba(255, 128, 109, 0.13);
}
.surface-label,
.depth-label {
padding: 5px 8px;
border-radius: 7px;
background: rgba(9, 28, 43, 0.72);
color: #9cd9ee;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.depth-label {
color: #ffad9f;
}
.equality-label {
padding: 8px 12px;
border: 1px solid rgba(84, 223, 241, 0.24);
border-radius: 999px;
background: rgba(10, 37, 51, 0.8);
color: #baf5ff;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.1em;
}
@media (max-width: 820px) {
.legend,
.hint,
.surface-label,
.depth-label {
display: none;
}
.hero {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
.hero p {
margin: 9px 0 11px;
}
.controls {
bottom: 12px;
gap: 10px;
padding: 11px;
}
.divider {
display: none;
}
#reset {
padding: 9px;
}
.vessel-label {
gap: 5px;
padding: 5px 7px;
}
.vessel-index {
width: 20px;
height: 20px;
}
.vessel-label b {
font-size: 9px;
}
.vessel-label small {
font-size: 8px;
}
}
@media (max-width: 520px) {
.hero p {
display: none;
}
.equation {
margin-top: 11px;
font-size: 10px;
}
.depth-control {
grid-template-columns: 1fr auto;
}
.depth-control label {
display: none;
}
#reset {
font-size: 0;
}
#reset::after {
content: "↺";
font-size: 18px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels"></div>
<section class="hero">
<div class="eyebrow">Fluid Mechanics / Hydrostatics</div>
<h1>Equal depth.<br />Equal pressure.</h1>
<p>
Three containers hold different amounts of fresh water, but their surfaces
are level. At any shared depth below that surface, the pressure is equal.
</p>
<div class="equation" id="equation" aria-live="polite"></div>
</section>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Scene key</div>
<div class="legend-row">
<span class="swatch"></span>
<span>Fresh water</span>
</div>
<div class="legend-row">
<span class="swatch ring"></span>
<span>Pressure measurement</span>
</div>
<div class="legend-row">
<span class="swatch dash"></span>
<span>Equal-depth reference</span>
</div>
</aside>
<section class="controls" aria-label="Scene controls">
<div class="depth-control">
<label for="depth">Probe depth below surface</label>
<input
id="depth"
type="range"
min="0.35"
max="2.40"
step="0.05"
value="1.55"
/>
<output id="depth-value" for="depth">1.55 m</output>
</div>
<div class="divider"></div>
<button id="reset" type="button" title="Reset camera">Reset camera</button>
</section>
<div class="hint">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";
const sceneHost = document.getElementById("scene");
const labelsHost = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111e);
scene.fog = new THREE.Fog(0x07111e, 17, 34);
const camera = new THREE.PerspectiveCamera(
42,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const world = new THREE.Group();
scene.add(world);
const hemisphere = new THREE.HemisphereLight(0xc9efff, 0x07101b, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const coralLight = new THREE.PointLight(0xff745e, 35, 20);
coralLight.position.set(-6, 4, 5);
scene.add(coralLight);
const cyanLight = new THREE.PointLight(0x41d9ff, 38, 22);
cyanLight.position.set(6, 3.5, -3);
scene.add(cyanLight);
const BASE_Y = 0.24;
const SHELL_HEIGHT = 3.05;
const WATER_BOTTOM = BASE_Y + 0.08;
const SURFACE_Y = BASE_Y + 2.78;
const FILL_HEIGHT = SURFACE_Y - WATER_BOTTOM;
const OVERLAY_Z = 1.55;
const positions = [-4.2, 0, 4.2];
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x36cfe3,
roughness: 0.18,
metalness: 0,
transparent: true,
opacity: 0.7,
clearcoat: 1,
clearcoatRoughness: 0.12,
side: THREE.DoubleSide,
depthWrite: false
});
const surfaceMaterial = new THREE.MeshPhysicalMaterial({
color: 0x9af5ff,
emissive: 0x164e5b,
emissiveIntensity: 0.38,
roughness: 0.14,
metalness: 0,
transparent: true,
opacity: 0.86,
side: THREE.DoubleSide,
depthWrite: false
});
function shellMaterial(color) {
return new THREE.MeshPhysicalMaterial({
color,
roughness: 0.28,
metalness: 0.12,
transparent: true,
opacity: 0.24,
clearcoat: 0.8,
side: THREE.DoubleSide,
depthWrite: false
});
}
function solidMaterial(color) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.35,
metalness: 0.25
});
}
function edgeMaterial(color) {
return new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.76
});
}
function addEdges(mesh, color, threshold = 25) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, threshold),
edgeMaterial(color)
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.renderOrder = 4;
world.add(edges);
return edges;
}
function addCylinderPedestal(x, radius, accent) {
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.06, 0.24, 64),
solidMaterial(0x12273a)
);
pedestal.position.set(x, 0.12, 0);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
world.add(pedestal);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.96, 0.018, 8, 64),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.75
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.245, 0);
world.add(ring);
}
function addBoxPedestal(x, width, depth, accent) {
const pedestal = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.24, depth),
solidMaterial(0x12273a)
);
pedestal.position.set(x, 0.12, 0);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
world.add(pedestal);
const line = new THREE.LineSegments(
new THREE.EdgesGeometry(pedestal.geometry),
edgeMaterial(accent)
);
line.position.copy(pedestal.position);
world.add(line);
}
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 34),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.92,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.01;
ground.receiveShadow = true;
world.add(ground);
const grid = new THREE.GridHelper(38, 38, 0x29475f, 0x14283a);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.42;
world.add(grid);
// ------------------------------------------------------------------
// Shared helpers
// ------------------------------------------------------------------
function profileRadiusAt(profile, y) {
if (y <= profile[0][1]) return profile[0][0];
for (let i = 1; i < profile.length; i++) {
const [r0, y0] = profile[i - 1];
const [r1, y1] = profile[i];
if (y <= y1) {
const t = (y - y0) / (y1 - y0);
return THREE.MathUtils.lerp(r0, r1, t);
}
}
return profile[profile.length - 1][0];
}
function frustumVolume(points) {
let volume = 0;
for (let i = 1; i < points.length; i++) {
const [r0, y0] = points[i - 1];
const [r1, y1] = points[i];
const h = y1 - y0;
volume +=
(Math.PI * h * (r0 * r0 + r0 * r1 + r1 * r1)) / 3;
}
return volume;
}
function horizontalCircle(radius, y, material) {
const mesh = new THREE.Mesh(
new THREE.CircleGeometry(radius, 64),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = y;
mesh.renderOrder = 3;
world.add(mesh);
return mesh;
}
function horizontalRing(radius, y, color) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(radius - 0.025, radius + 0.025, 64),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.75,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = y;
ring.renderOrder = 4;
world.add(ring);
return ring;
}
// ------------------------------------------------------------------
// 01: Flared vessel
// ------------------------------------------------------------------
const flaredProfile = [
[0.72, 0.00],
[0.80, 0.18],
[1.00, 0.90],
[1.24, 2.00],
[1.36, 2.78],
[1.36, SHELL_HEIGHT]
];
const flaredColor = 0xffb45f;
addCylinderPedestal(positions[0], 1.52, flaredColor);
const flaredGeometry = new THREE.LatheGeometry(
flaredProfile.map(([r, y]) => new THREE.Vector2(r, y)),
64
);
const flaredShell = new THREE.Mesh(
flaredGeometry,
shellMaterial(flaredColor)
);
flaredShell.position.y = BASE_Y;
flaredShell.renderOrder = 1;
world.add(flaredShell);
addEdges(flaredShell, flaredColor, 18);
const flaredBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.77, 0.77, 0.12, 64),
solidMaterial(flaredColor)
);
flaredBase.position.set(positions[0], BASE_Y + 0.055, 0);
flaredBase.castShadow = true;
world.add(flaredBase);
const flaredRim = new THREE.Mesh(
new THREE.TorusGeometry(1.36, 0.055, 12, 64),
solidMaterial(flaredColor)
);
flaredRim.rotation.x = Math.PI / 2;
flaredRim.position.set(positions[0], BASE_Y + SHELL_HEIGHT, 0);
flaredRim.castShadow = true;
world.add(flaredRim);
const flaredInnerProfile = [
[0, 0.08],
[profileRadiusAt(flaredProfile, 0.08) - 0.1, 0.08],
[profileRadiusAt(flaredProfile, 0.18) - 0.1, 0.18],
[profileRadiusAt(flaredProfile, 0.90) - 0.1, 0.90],
[profileRadiusAt(flaredProfile, 2.00) - 0.1, 2.00],
[profileRadiusAt(flaredProfile, 2.78) - 0.1, 2.78]
];
const flaredWaterGeometry = new THREE.LatheGeometry(
flaredInnerProfile.map(([r, y]) => new THREE.Vector2(r, y)),
64
);
const flaredWater = new THREE.Mesh(
flaredWaterGeometry,
waterMaterial
);
flaredWater.position.set(positions[0], BASE_Y, 0);
flaredWater.renderOrder = 2;
world.add(flaredWater);
const flaredSurfaceRadius = flaredInnerProfile.at(-1)[0];
horizontalCircle(
flaredSurfaceRadius,
SURFACE_Y,
surfaceMaterial
).position.x = positions[0];
horizontalRing(
flaredSurfaceRadius,
SURFACE_Y + 0.006,
0xa8f8ff
).position.x = positions[0];
const flaredVolume = frustumVolume(flaredInnerProfile);
// ------------------------------------------------------------------
// 02: Narrow cylindrical column
// ------------------------------------------------------------------
const narrowColor = 0x63e0c0;
addCylinderPedestal(positions[1], 0.94, narrowColor);
const narrowGeometry = new THREE.CylinderGeometry(
0.78,
0.78,
SHELL_HEIGHT,
64,
1,
true
);
const narrowShell = new THREE.Mesh(
narrowGeometry,
shellMaterial(narrowColor)
);
narrowShell.position.set(positions[1], BASE_Y + SHELL_HEIGHT / 2, 0);
narrowShell.renderOrder = 1;
world.add(narrowShell);
addEdges(narrowShell, narrowColor, 22);
const narrowBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.81, 0.81, 0.12, 64),
solidMaterial(narrowColor)
);
narrowBase.position.set(positions[1], BASE_Y + 0.055, 0);
narrowBase.castShadow = true;
world.add(narrowBase);
const narrowRim = new THREE.Mesh(
new THREE.TorusGeometry(0.78, 0.055, 12, 64),
solidMaterial(narrowColor)
);
narrowRim.rotation.x = Math.PI / 2;
narrowRim.position.set(positions[1], BASE_Y + SHELL_HEIGHT, 0);
narrowRim.castShadow = true;
world.add(narrowRim);
const narrowWater = new THREE.Mesh(
new THREE.CylinderGeometry(0.68, 0.68, FILL_HEIGHT, 64),
waterMaterial
);
narrowWater.position.set(
positions[1],
WATER_BOTTOM + FILL_HEIGHT / 2,
0
);
narrowWater.renderOrder = 2;
world.add(narrowWater);
horizontalCircle(0.68, SURFACE_Y, surfaceMaterial).position.x =
positions[1];
horizontalRing(0.68, SURFACE_Y + 0.006, 0xa8f8ff).position.x =
positions[1];
const narrowVolume = Math.PI * 0.68 * 0.68 * FILL_HEIGHT;
// ------------------------------------------------------------------
// 03: Rectangular tank
// ------------------------------------------------------------------
const rectangleColor = 0xa891ff;
const rectangleWidth = 1.65;
const rectangleDepth = 1.28;
const wallThickness = 0.09;
addBoxPedestal(
positions[2],
rectangleWidth + 0.28,
rectangleDepth + 0.28,
rectangleColor
);
const rectangleShellMaterial = shellMaterial(rectangleColor);
const wallSpecs = [
{
size: [rectangleWidth, SHELL_HEIGHT, wallThickness],
pos: [0, SHELL_HEIGHT / 2, rectangleDepth / 2 - wallThickness / 2]
},
{
size: [rectangleWidth, SHELL_HEIGHT, wallThickness],
pos: [0, SHELL_HEIGHT / 2, -rectangleDepth / 2 + wallThickness / 2]
},
{
size: [wallThickness, SHELL_HEIGHT, rectangleDepth - wallThickness * 2],
pos: [rectangleWidth / 2 - wallThickness / 2, SHELL_HEIGHT / 2, 0]
},
{
size: [wallThickness, SHELL_HEIGHT, rectangleDepth - wallThickness * 2],
pos: [-rectangleWidth / 2 + wallThickness / 2, SHELL_HEIGHT / 2, 0]
}
];
for (const spec of wallSpecs) {
const wall = new THREE.Mesh(
new THREE.BoxGeometry(...spec.size),
rectangleShellMaterial
);
wall.position.set(
positions[2] + spec.pos[0],
BASE_Y + spec.pos[1],
spec.pos[2]
);
wall.renderOrder = 1;
world.add(wall);
addEdges(wall, rectangleColor, 15);
}
const rectangleBase = new THREE.Mesh(
new THREE.BoxGeometry(
rectangleWidth + 0.08,
0.12,
rectangleDepth + 0.08
),
solidMaterial(rectangleColor)
);
rectangleBase.position.set(positions[2], BASE_Y + 0.055, 0);
rectangleBase.castShadow = true;
world.add(rectangleBase);
const rimParts = [
{
size: [rectangleWidth + 0.12, 0.1, 0.1],
pos: [0, rectangleDepth / 2]
},
{
size: [rectangleWidth + 0.12, 0.1, 0.1],
pos: [0, -rectangleDepth / 2]
},
{
size: [0.1, 0.1, rectangleDepth],
pos: [rectangleWidth / 2, 0]
},
{
size: [0.1, 0.1, rectangleDepth],
pos: [-rectangleWidth / 2, 0]
}
];
for (const spec of rimParts) {
const rim = new THREE.Mesh(
new THREE.BoxGeometry(...spec.size),
solidMaterial(rectangleColor)
);
rim.position.set(
positions[2] + spec.pos[0],
BASE_Y + SHELL_HEIGHT,
spec.pos[1]
);
rim.castShadow = true;
world.add(rim);
}
const innerWidth = rectangleWidth - wallThickness * 2;
const innerDepth = rectangleDepth - wallThickness * 2;
const rectangleWater = new THREE.Mesh(
new THREE.BoxGeometry(innerWidth, FILL_HEIGHT, innerDepth),
waterMaterial
);
rectangleWater.position.set(
positions[2],
WATER_BOTTOM + FILL_HEIGHT / 2,
0
);
rectangleWater.renderOrder = 2;
world.add(rectangleWater);
const rectangleSurface = new THREE.Mesh(
new THREE.PlaneGeometry(innerWidth, innerDepth),
surfaceMaterial
);
rectangleSurface.rotation.x = -Math.PI / 2;
rectangleSurface.position.set(positions[2], SURFACE_Y, 0);
rectangleSurface.renderOrder = 3;
world.add(rectangleSurface);
const rectangleSurfaceOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-innerWidth / 2, 0, -innerDepth / 2),
new THREE.Vector3(innerWidth / 2, 0, -innerDepth / 2),
new THREE.Vector3(innerWidth / 2, 0, innerDepth / 2),
new THREE.Vector3(-innerWidth / 2, 0, innerDepth / 2)
]),
new THREE.LineBasicMaterial({
color: 0xa8f8ff,
transparent: true,
opacity: 0.78
})
);
rectangleSurfaceOutline.position.set(positions[2], SURFACE_Y + 0.007, 0);
rectangleSurfaceOutline.renderOrder = 4;
world.add(rectangleSurfaceOutline);
const rectangleVolume = innerWidth * innerDepth * FILL_HEIGHT;
// ------------------------------------------------------------------
// Suspended particles make the water volumes easy to perceive.
// ------------------------------------------------------------------
const particleSystems = [];
function createParticles({
x,
type,
radiusAt = null,
halfWidth = 0,
halfDepth = 0
}) {
const count = 30;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const data = [];
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const radial = Math.sqrt(Math.random()) * 0.78;
const item = {
y: Math.random() * FILL_HEIGHT,
speed: 0.08 + Math.random() * 0.13,
angle,
radial,
px: (Math.random() * 2 - 1) * halfWidth * 0.82,
pz: (Math.random() * 2 - 1) * halfDepth * 0.82,
phase: Math.random() * Math.PI * 2
};
data.push(item);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.BufferAttribute(colors, 3)
);
const material = new THREE.PointsMaterial({
size: 0.052,
sizeAttenuation: true,
transparent: true,
opacity: 0.72,
vertexColors: true,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const points = new THREE.Points(geometry, material);
points.renderOrder = 4;
world.add(points);
particleSystems.push({
points,
geometry,
data,
x,
type,
radiusAt,
halfWidth,
halfDepth
});
}
createParticles({
x: positions[0],
type: "circle",
radiusAt: (y) => profileRadiusAt(flaredProfile, y) - 0.14
});
createParticles({
x: positions[1],
type: "circle",
radiusAt: () => 0.59
});
createParticles({
x: positions[2],
type: "box",
halfWidth: innerWidth / 2,
halfDepth: innerDepth / 2
});
// ------------------------------------------------------------------
// HTML labels projected from world coordinates.
// ------------------------------------------------------------------
const labels = [];
function addWorldLabel(className, html, anchor) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
labelsHost.appendChild(element);
const label = {
element,
anchor: anchor.clone(),
visible: true
};
labels.push(label);
return label;
}
const vesselData = [
{
index: "01",
name: "Flared vessel",
volume: flaredVolume,
accent: "#ffc46b",
x: positions[0]
},
{
index: "02",
name: "Narrow column",
volume: narrowVolume,
accent: "#63e0c0",
x: positions[1]
},
{
index: "03",
name: "Rectangular tank",
volume: rectangleVolume,
accent: "#b8a8ff",
x: positions[2]
}
];
for (const vessel of vesselData) {
addWorldLabel(
"vessel-label",
`
<span class="vessel-index"
style="--accent:${vessel.accent}">${vessel.index}</span>
<div>
<b>${vessel.name}</b>
<small>≈ ${vessel.volume.toFixed(1)} m³ water</small>
</div>
`,
new THREE.Vector3(vessel.x, 0.12, 1.25)
);
}
// ------------------------------------------------------------------
// Equal-depth measurement overlay
// ------------------------------------------------------------------
const surfaceLineMaterial = new THREE.LineDashedMaterial({
color: 0x9eddf4,
dashSize: 0.15,
gapSize: 0.1,
transparent: true,
opacity: 0.58,
depthTest: false
});
const depthLineMaterial = new THREE.LineDashedMaterial({
color: 0xff806d,
dashSize: 0.13,
gapSize: 0.09,
transparent: true,
opacity: 0.8,
depthTest: false
});
const surfaceLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-5.3, SURFACE_Y, OVERLAY_Z),
new THREE.Vector3(5.3, SURFACE_Y, OVERLAY_Z)
]),
surfaceLineMaterial
);
surfaceLine.computeLineDistances();
surfaceLine.renderOrder = 10;
surfaceLine.frustumCulled = false;
world.add(surfaceLine);
const depthLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-5.3, SURFACE_Y - 1.55, OVERLAY_Z),
new THREE.Vector3(5.3, SURFACE_Y - 1.55, OVERLAY_Z)
]),
depthLineMaterial
);
depthLine.computeLineDistances();
depthLine.renderOrder = 10;
depthLine.frustumCulled = false;
world.add(depthLine);
const verticalLines = [];
for (const x of positions) {
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, SURFACE_Y, OVERLAY_Z),
new THREE.Vector3(x, SURFACE_Y - 1.55, OVERLAY_Z)
]),
depthLineMaterial
);
line.computeLineDistances();
line.renderOrder = 10;
line.frustumCulled = false;
world.add(line);
verticalLines.push(line);
}
function createPressureMarker(x) {
const group = new THREE.Group();
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.17, 0.225, 48),
new THREE.MeshBasicMaterial({
color: 0xff806d,
transparent: true,
opacity: 0.96,
side: THREE.DoubleSide,
depthTest: false
})
);
ring.renderOrder = 20;
group.add(ring);
const back = new THREE.Mesh(
new THREE.CircleGeometry(0.15, 40),
new THREE.MeshBasicMaterial({
color: 0x173044,
transparent: true,
opacity: 0.94,
side: THREE.DoubleSide,
depthTest: false
})
);
back.position.z = -0.002;
back.renderOrder = 19;
group.add(back);
const fill = new THREE.Mesh(
new THREE.CircleGeometry(0.115, 40),
new THREE.MeshBasicMaterial({
color: 0xff806d,
transparent: true,
opacity: 0.88,
side: THREE.DoubleSide,
depthTest: false
})
);
fill.position.z = 0.003;
fill.renderOrder = 21;
group.add(fill);
const triangleGeometry = new THREE.BufferGeometry();
triangleGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0.105, 0.006,
-0.052, 0.005, 0.006,
0.052, 0.005, 0.006
], 3)
);
const triangle = new THREE.Mesh(
triangleGeometry,
new THREE.MeshBasicMaterial({
color: 0xfff4ee,
side: THREE.DoubleSide,
depthTest: false
})
);
triangle.renderOrder = 22;
group.add(triangle);
group.position.set(x, SURFACE_Y - 1.55, OVERLAY_Z + 0.025);
world.add(group);
return { group, ring, fill };
}
const markers = positions.map(createPressureMarker);
const pressureLabels = positions.map((x) =>
addWorldLabel(
"pressure-label",
"15.2 kPa",
new THREE.Vector3(x, SURFACE_Y - 1.55 + 0.4, OVERLAY_Z)
)
);
addWorldLabel(
"surface-label",
"SAME SURFACE HEIGHT",
new THREE.Vector3(4.95, SURFACE_Y + 0.14, OVERLAY_Z)
);
const depthLabel = addWorldLabel(
"depth-label",
"DEPTH 1.55 m",
new THREE.Vector3(-5.05, SURFACE_Y - 1.55, OVERLAY_Z)
);
addWorldLabel(
"equality-label",
"p₁ = p₂ = p₃",
new THREE.Vector3(0, SURFACE_Y + 0.52, OVERLAY_Z)
);
const depthInput = document.getElementById("depth");
const depthValue = document.getElementById("depth-value");
const equation = document.getElementById("equation");
function pressureAtDepth(depth) {
// rho = 1000 kg/m^3, g = 9.81 m/s^2, result in kPa
return (1000 * 9.81 * depth) / 1000;
}
function updateMeasurement() {
const depth = Number(depthInput.value);
const pressure = pressureAtDepth(depth);
const probeY = SURFACE_Y - depth;
depthValue.textContent = `${depth.toFixed(2)} m`;
equation.innerHTML =
`<strong>ρgh</strong> = 1000 × 9.81 × ${depth.toFixed(2)}` +
` ≈ <strong>${pressure.toFixed(1)} kPa</strong>`;
const depthPositions = depthLine.geometry.attributes.position.array;
depthPositions[0] = -5.3;
depthPositions[1] = probeY;
depthPositions[2] = OVERLAY_Z;
depthPositions[3] = 5.3;
depthPositions[4] = probeY;
depthPositions[5] = OVERLAY_Z;
depthLine.geometry.attributes.position.needsUpdate = true;
depthLine.computeLineDistances();
verticalLines.forEach((line, index) => {
const array = line.geometry.attributes.position.array;
array[0] = positions[index];
array[1] = SURFACE_Y;
array[2] = OVERLAY_Z;
array[3] = positions[index];
array[4] = probeY;
array[5] = OVERLAY_Z;
line.geometry.attributes.position.needsUpdate = true;
line.computeLineDistances();
});
markers.forEach((marker, index) => {
marker.group.position.set(
positions[index],
probeY,
OVERLAY_Z + 0.025
);
const normalized = THREE.MathUtils.clamp(pressure / 24, 0, 1);
marker.fill.scale.setScalar(0.62 + normalized * 0.38);
pressureLabels[index].anchor.set(
positions[index],
probeY + 0.4,
OVERLAY_Z
);
pressureLabels[index].element.textContent = `${pressure.toFixed(1)} kPa`;
});
depthLabel.anchor.set(-5.05, probeY, OVERLAY_Z);
depthLabel.element.textContent = `DEPTH ${depth.toFixed(2)} m`;
}
depthInput.addEventListener("input", updateMeasurement);
updateMeasurement();
// ------------------------------------------------------------------
// Direct camera controls: no addons or external control scripts.
// ------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.48, 0);
let cameraRadius = window.innerWidth < 720 ? 23 : 14.2;
let cameraTheta = 0.1;
let cameraPhi = 1.18;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const horizontalRadius = cameraRadius * Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + horizontalRadius * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= dx * 0.005;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.004,
0.66,
1.43
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (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();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
8.5,
32
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
cameraTheta = 0.1;
cameraPhi = 1.18;
cameraRadius = window.innerWidth < 720 ? 23 : 14.2;
});
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
// ------------------------------------------------------------------
// Animation and projected labels
// ------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function updateParticles(dt) {
for (const system of particleSystems) {
const positionArray = system.geometry.attributes.position.array;
const colorArray = system.geometry.attributes.color.array;
system.data.forEach((item, index) => {
item.y += item.speed * dt;
if (item.y > FILL_HEIGHT) {
item.y = 0.03;
}
let px = item.px;
let pz = item.pz;
if (system.type === "circle") {
const shellY = item.y + (WATER_BOTTOM - BASE_Y);
const radius = system.radiusAt(shellY);
const drift = reducedMotion ? 0 : Math.sin(clock.elapsedTime + item.phase) * 0.018;
px = Math.cos(item.angle) * item.radial * radius + drift;
pz = Math.sin(item.angle) * item.radial * radius;
}
const arrayIndex = index * 3;
positionArray[arrayIndex] = system.x + px;
positionArray[arrayIndex + 1] = WATER_BOTTOM + item.y;
positionArray[arrayIndex + 2] = pz;
const brightness = 0.28 + (item.y / FILL_HEIGHT) * 0.58;
colorArray[arrayIndex] = brightness * 0.68;
colorArray[arrayIndex + 1] = brightness;
colorArray[arrayIndex + 2] = brightness;
});
system.geometry.attributes.position.needsUpdate = true;
system.geometry.attributes.color.needsUpdate = true;
}
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -180 &&
x < width + 180 &&
y > -80 &&
y < height + 80;
label.element.style.display = visible ? "block" : "none";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateCamera();
markers.forEach((marker) => {
marker.group.quaternion.copy(camera.quaternion);
const pulse = reducedMotion ? 1 : 1 + Math.sin(time * 2.1) * 0.025;
marker.ring.scale.setScalar(pulse);
});
surfaceMaterial.opacity = reducedMotion
? 0.86
: 0.84 + Math.sin(time * 1.4) * 0.035;
updateParticles(dt);
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```