Prompt specification
Build or customize the Three.js 3D scene "Dam wall pressure teaching section" 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: Dam wall pressure teaching section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/dam-wall-pressure-teaching-section-x1487
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a voxel reservoir and dam-wall teaching section. Cut through the water body and wall so the depth, flat free surface, and wetted face are visible together. Draw pressure arrows normal to the wall, increasing in length with depth according to a stated static-fluid model. Place a separate resultant-force arrow and explain that it summarizes the distributed load rather than being another local pressure value. A water-level slider updates the submerged region and both representations. Use a simple vertical wall and explicitly declared fluid density and gravity, avoiding any claim that this is a validated structural dam design.
Working Three.js Starter (dam-wall-pressure-teaching-section-x1487):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Reservoir and Vertical Dam-Wall Teaching Section</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 18, 32, 0.91);
--border: rgba(148, 163, 184, 0.25);
--text: #e5eef8;
--muted: #a9bacd;
--cyan: #38d6f6;
--gold: #ffc857;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111e;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(12px);
}
h1 {
margin: 0 0 7px;
font-size: 21px;
line-height: 1.2;
letter-spacing: 0.01em;
}
.subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.control-block {
margin: 15px 0;
padding: 13px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 14px;
font-weight: 650;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.readouts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 12px;
}
.readout {
padding: 9px 8px;
border-radius: 9px;
background: rgba(56, 214, 246, 0.07);
text-align: center;
}
.readout strong {
display: block;
color: var(--cyan);
font-size: 16px;
font-variant-numeric: tabular-nums;
}
.readout span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.2;
}
.model {
font-size: 13px;
line-height: 1.48;
}
.model p {
margin: 8px 0;
}
.equation {
padding: 9px 10px;
border-left: 3px solid var(--cyan);
border-radius: 4px;
background: rgba(56, 214, 246, 0.07);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.legend {
display: grid;
gap: 9px;
margin-top: 12px;
}
.legend-row {
display: grid;
grid-template-columns: 34px 1fr;
gap: 9px;
align-items: start;
color: var(--muted);
font-size: 12px;
line-height: 1.42;
}
.swatch {
height: 4px;
margin-top: 7px;
border-radius: 4px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(56, 214, 246, 0.5);
}
.swatch.gold {
background: var(--gold);
box-shadow: 0 0 10px rgba(255, 200, 87, 0.5);
}
.legend-row strong {
color: var(--text);
}
.disclaimer {
margin-top: 15px;
padding: 11px;
border: 1px solid rgba(255, 200, 87, 0.32);
border-radius: 10px;
background: rgba(255, 200, 87, 0.07);
color: #f7dfaa;
font-size: 12px;
line-height: 1.42;
}
#camera-hint {
position: fixed;
z-index: 5;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(8, 18, 32, 0.76);
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
@media (max-width: 700px) {
#panel {
top: 10px;
left: 10px;
width: min(350px, calc(100vw - 20px));
max-height: 58vh;
padding: 15px;
}
h1 {
font-size: 18px;
}
#camera-hint {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<aside id="panel" aria-label="Hydrostatic pressure teaching controls and model">
<h1>Voxel Reservoir & Vertical Wall</h1>
<p class="subtitle">
A cutaway teaching section showing a flat free surface, submerged wall
face, local hydrostatic pressure, and the equivalent resultant load.
</p>
<section class="control-block">
<label class="control-label" for="water-level">
Water level <output id="level-output" for="water-level">3.20 m</output>
</label>
<input
id="water-level"
type="range"
min="2"
max="4.8"
step="0.05"
value="3.2"
>
<div class="range-ends">
<span>2.0 m</span>
<span>4.8 m</span>
</div>
<div class="readouts" aria-live="polite">
<div class="readout">
<strong id="pmax-output">31.4 kPa</strong>
<span>pressure at bed</span>
</div>
<div class="readout">
<strong id="force-output">301.3 kN</strong>
<span>resultant force</span>
</div>
<div class="readout">
<strong id="cop-output">1.07 m</strong>
<span>force height above bed</span>
</div>
</div>
</section>
<section class="control-block model">
<strong>Declared static-fluid model</strong>
<p>
Fluid density:
<strong>ρ = 1000 kg/m³</strong><br>
Gravity:
<strong>g = 9.81 m/s²</strong><br>
Wall-face width into the page:
<strong>b = 6.0 m</strong>
</p>
<div class="equation">
Local gauge pressure:<br>
p(h) = ρgh<br><br>
Resultant on the wetted rectangle:<br>
F<sub>R</sub> = ½ρgbH²
</div>
<p>
Here, <strong>h</strong> is vertical depth below the free surface and
<strong>H</strong> is the current water height above the bed.
The resultant acts at <strong>H/3 above the bed</strong>.
</p>
<div class="legend">
<div class="legend-row">
<div class="swatch"></div>
<div>
<strong>Cyan: local pressure arrows.</strong>
Each arrow is normal to the wall and points downstream. Its
length is proportional to p(h), using
<strong>0.08 m per kPa</strong> for display.
</div>
</div>
<div class="legend-row">
<div class="swatch gold"></div>
<div>
<strong>Gold: equivalent resultant-force arrow.</strong>
It summarizes the entire distributed pressure load; it is
<strong>not another local pressure value</strong>. Because it is a
force rather than a pressure, it uses a separate display scale,
<strong>0.0055 m per kN</strong>.
</div>
</div>
</div>
</section>
<div class="disclaimer">
<strong>Educational schematic only.</strong>
This is not a validated structural dam design, stability analysis, or
engineering load case. It omits seepage, uplift, dynamic loads, erosion,
foundation interaction, reinforcement, and other structural factors.
</div>
</aside>
<div id="camera-hint">Drag to orbit · wheel to zoom · double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Declared physical model and schematic dimensions
// -------------------------------------------------------------------------
const MODEL = Object.freeze({
rho: 1000, // kg/m³
g: 9.81, // m/s²
wallWidth: 6.0, // m, into the page
wallHeight: 5.4, // m
wallThickness: 0.72,
reservoirLength: 6.4,
wallDepth: 6.0,
pressureScale: 0.08, // display metres per kPa
forceScale: 0.0055 // display metres per kN
});
const WALL_LEFT = -MODEL.wallThickness / 2;
const WALL_RIGHT = MODEL.wallThickness / 2;
const WATER_LEFT = WALL_LEFT - MODEL.reservoirLength;
const WATER_CENTER_X = (WATER_LEFT + WALL_LEFT) / 2;
const WALL_CENTER_Z = -MODEL.wallDepth / 2;
// -------------------------------------------------------------------------
// Renderer, scene, and direct camera controls (no addons)
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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",
"Interactive cutaway reservoir and vertical dam wall"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111e);
scene.fog = new THREE.Fog(0x07111e, 19, 36);
const camera = new THREE.PerspectiveCamera(
42,
1,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(-0.65, 1.85, -2.75),
radius: 14.0,
theta: -0.72,
phi: 1.12
};
const initialOrbit = {
target: orbit.target.clone(),
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
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);
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.35,
1.48
);
});
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
8.0,
24.0
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.target.copy(initialOrbit.target);
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
// -------------------------------------------------------------------------
// Lighting and static scene geometry
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x182230, 2.0));
const sun = new THREE.DirectionalLight(0xffffff, 2.6);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x77bfff, 1.0);
fill.position.set(7, 5, -8);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x273544,
roughness: 0.95,
metalness: 0.02
});
const ground = new THREE.Mesh(
new THREE.BoxGeometry(17.5, 0.34, 10),
groundMaterial
);
ground.position.set(0.5, -0.19, -3);
ground.receiveShadow = true;
scene.add(ground);
const bedMaterial = new THREE.MeshStandardMaterial({
color: 0x51483d,
roughness: 1
});
const reservoirBed = new THREE.Mesh(
new THREE.BoxGeometry(MODEL.reservoirLength, 0.10, MODEL.wallDepth),
bedMaterial
);
reservoirBed.position.set(
WATER_CENTER_X,
-0.05,
WALL_CENTER_Z
);
reservoirBed.receiveShadow = true;
scene.add(reservoirBed);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x9ba7b4,
roughness: 0.82,
metalness: 0.025
});
const wall = new THREE.Mesh(
new THREE.BoxGeometry(
MODEL.wallThickness,
MODEL.wallHeight,
MODEL.wallDepth
),
wallMaterial
);
wall.position.set(0, MODEL.wallHeight / 2, WALL_CENTER_Z);
wall.castShadow = true;
wall.receiveShadow = true;
scene.add(wall);
const wallEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(wall.geometry),
new THREE.LineBasicMaterial({
color: 0xd7e1eb,
transparent: true,
opacity: 0.65
})
);
wallEdges.position.copy(wall.position);
scene.add(wallEdges);
// A narrow downstream apron makes the pressure direction easy to read.
const apron = new THREE.Mesh(
new THREE.BoxGeometry(5.2, 0.12, MODEL.wallDepth),
new THREE.MeshStandardMaterial({
color: 0x465463,
roughness: 0.92
})
);
apron.position.set(3.0, -0.06, WALL_CENTER_Z);
apron.receiveShadow = true;
scene.add(apron);
// -------------------------------------------------------------------------
// Water volume: the front half is omitted, making z = 0 a section plane
// -------------------------------------------------------------------------
const waterMaterial = new THREE.MeshPhongMaterial({
color: 0x1aa9db,
transparent: true,
opacity: 0.23,
depthWrite: false,
side: THREE.DoubleSide,
shininess: 65
});
const water = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
waterMaterial
);
water.renderOrder = 2;
scene.add(water);
const waterEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(1, 1, 1)),
new THREE.LineBasicMaterial({
color: 0x57d9ff,
transparent: true,
opacity: 0.68
})
);
waterEdges.renderOrder = 3;
scene.add(waterEdges);
// The exposed blue rectangle is the cut water section.
const waterSection = new THREE.Mesh(
new THREE.PlaneGeometry(MODEL.reservoirLength, 1),
new THREE.MeshBasicMaterial({
color: 0x0ea5e9,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
depthWrite: false
})
);
waterSection.position.z = 0.012;
waterSection.renderOrder = 3;
scene.add(waterSection);
// Separate flat free-surface sheet.
const freeSurface = new THREE.Mesh(
new THREE.PlaneGeometry(MODEL.reservoirLength, MODEL.wallDepth),
new THREE.MeshBasicMaterial({
color: 0x54d9ff,
transparent: true,
opacity: 0.31,
side: THREE.DoubleSide,
depthWrite: false
})
);
freeSurface.rotation.x = -Math.PI / 2;
freeSurface.renderOrder = 4;
scene.add(freeSurface);
const surfaceLinePositions = new Float32Array([
WATER_LEFT, 0, 0,
WALL_LEFT, 0, 0,
WALL_LEFT, 0, -MODEL.wallDepth,
WATER_LEFT, 0, -MODEL.wallDepth,
WATER_LEFT, 0, 0,
WALL_LEFT, 0, -MODEL.wallDepth
]);
const surfaceOutline = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.BufferAttribute(surfaceLinePositions, 3)
),
new THREE.LineBasicMaterial({
color: 0xa9edff,
transparent: true,
opacity: 0.95
})
);
surfaceOutline.renderOrder = 5;
scene.add(surfaceOutline);
// Teal overlay on the actual wall face, clipped dynamically to the
// current submerged height.
const wettedFace = new THREE.Mesh(
new THREE.PlaneGeometry(MODEL.wallDepth, 1),
new THREE.MeshBasicMaterial({
color: 0x22c7e8,
transparent: true,
opacity: 0.48,
side: THREE.DoubleSide,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1
})
);
wettedFace.rotation.y = -Math.PI / 2;
wettedFace.position.x = WALL_LEFT - 0.008;
wettedFace.position.z = WALL_CENTER_Z;
wettedFace.renderOrder = 4;
scene.add(wettedFace);
// -------------------------------------------------------------------------
// Arrow construction: cylinders and cones are oriented along +X
// -------------------------------------------------------------------------
function createArrow(color, shaftRadius, maximumHeadLength) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.97,
depthTest: false
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 12),
material
);
shaft.rotation.z = -Math.PI / 2;
shaft.renderOrder = 20;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(1, 1, 18),
material
);
head.rotation.z = -Math.PI / 2;
head.renderOrder = 21;
group.add(head);
function setLength(totalLength) {
const length = Math.max(totalLength, 0.02);
const headLength = Math.min(
maximumHeadLength,
Math.max(0.025, length * 0.34)
);
const shaftLength = Math.max(0.005, length - headLength);
shaft.scale.set(
shaftRadius,
shaftLength,
shaftRadius
);
shaft.position.x = shaftLength / 2;
head.scale.set(
shaftRadius * 2.15,
headLength,
shaftRadius * 2.15
);
head.position.x = shaftLength + headLength / 2;
}
return { group, setLength };
}
const pressureArrowCount = 9;
const pressureArrows = [];
for (let i = 0; i < pressureArrowCount; i++) {
const arrow = createArrow(0x38d6f6, 0.043, 0.15);
scene.add(arrow.group);
pressureArrows.push(arrow);
}
// The gold arrow is deliberately thicker and uses a different scale.
const resultantArrow = createArrow(0xffc857, 0.12, 0.32);
resultantArrow.group.renderOrder = 24;
scene.add(resultantArrow.group);
// -------------------------------------------------------------------------
// Canvas-sprite labels
// -------------------------------------------------------------------------
function roundedRectPath(context, x, y, w, h, r) {
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + w - r, y);
context.quadraticCurveTo(x + w, y, x + w, y + r);
context.lineTo(x + w, y + h - r);
context.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
context.lineTo(x + r, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function makeLabel(initialText, accent = "#38d6f6", worldWidth = 2.7) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 160;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 0.25, 1);
sprite.renderOrder = 40;
function update(text) {
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(5, 14, 27, 0.88)";
roundedRectPath(context, 6, 6, 628, 148, 22);
context.fill();
context.strokeStyle = accent;
context.lineWidth = 5;
roundedRectPath(context, 6, 6, 628, 148, 22);
context.stroke();
context.fillStyle = accent;
context.fillRect(20, 25, 8, 110);
let fontSize = 43;
context.font = `700 ${fontSize}px system-ui, sans-serif`;
while (
context.measureText(text).width > 570 &&
fontSize > 22
) {
fontSize -= 2;
context.font = `700 ${fontSize}px system-ui, sans-serif`;
}
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#edf7ff";
context.fillText(text, 330, 81);
texture.needsUpdate = true;
}
update(initialText);
scene.add(sprite);
return { sprite, update };
}
const freeSurfaceLabel = makeLabel(
"flat free surface",
"#38d6f6",
3.0
);
const wettedFaceLabel = makeLabel(
"wetted wall face",
"#38d6f6",
2.75
);
const wallLabel = makeLabel(
"vertical wall",
"#cbd5e1",
2.3
);
const resultantLabel = makeLabel(
"resultant force",
"#ffc857",
3.25
);
const depthLabel = makeLabel(
"h = depth",
"#38d6f6",
1.65
);
const sectionLabel = makeLabel(
"cutaway section",
"#94a3b8",
2.15
);
// Three small labels on selected pressure arrows.
const pressureLabelIndices = [1, 4, 7];
const pressureLabels = pressureLabelIndices.map(() =>
makeLabel("p = 0 kPa", "#38d6f6", 1.55)
);
// Static depth ruler with half-metre ticks.
const rulerPositions = [];
const rulerX = WATER_LEFT + 0.22;
rulerPositions.push(
rulerX, 0, 0.08,
rulerX, MODEL.wallHeight, 0.08
);
for (let y = 0; y <= MODEL.wallHeight + 0.001; y += 0.5) {
rulerPositions.push(
rulerX - 0.09, y, 0.08,
rulerX + 0.09, y, 0.08
);
}
const ruler = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(rulerPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0xb5d6e8,
transparent: true,
opacity: 0.68
})
);
scene.add(ruler);
// Dynamic bracket measuring h from the free surface to one pressure arrow.
const depthBracket = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color: 0x75e7ff,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
depthBracket.renderOrder = 25;
scene.add(depthBracket);
const depthBracketCaps = new THREE.LineSegments(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0x75e7ff,
depthTest: false
})
);
depthBracketCaps.renderOrder = 25;
scene.add(depthBracketCaps);
// -------------------------------------------------------------------------
// Dynamic model update
// -------------------------------------------------------------------------
const levelSlider = document.querySelector("#water-level");
const levelOutput = document.querySelector("#level-output");
const pmaxOutput = document.querySelector("#pmax-output");
const forceOutput = document.querySelector("#force-output");
const copOutput = document.querySelector("#cop-output");
function setLabelPosition(label, x, y, z) {
label.sprite.position.set(x, y, z);
}
function updateModel() {
const H = Number(levelSlider.value);
const pBedPa = MODEL.rho * MODEL.g * H;
const pBedKPa = pBedPa / 1000;
const resultantNewtons =
0.5 *
MODEL.rho *
MODEL.g *
MODEL.wallWidth *
H *
H;
const resultantKN = resultantNewtons / 1000;
const forceHeight = H / 3;
levelOutput.value = `${H.toFixed(2)} m`;
pmaxOutput.textContent = `${pBedKPa.toFixed(1)} kPa`;
forceOutput.textContent = `${resultantKN.toFixed(1)} kN`;
copOutput.textContent = `${forceHeight.toFixed(2)} m`;
// Water volume, exposed section, and free surface.
water.scale.set(
MODEL.reservoirLength,
H,
MODEL.wallDepth
);
water.position.set(
WATER_CENTER_X,
H / 2,
WALL_CENTER_Z
);
waterEdges.scale.copy(water.scale);
waterEdges.position.copy(water.position);
waterSection.scale.set(1, H, 1);
waterSection.position.set(
WATER_CENTER_X,
H / 2,
0.012
);
freeSurface.position.set(
WATER_CENTER_X,
H + 0.006,
WALL_CENTER_Z
);
for (let i = 0; i < surfaceLinePositions.length; i += 3) {
surfaceLinePositions[i + 1] = H + 0.009;
}
surfaceOutline.geometry.attributes.position.needsUpdate = true;
surfaceOutline.geometry.computeBoundingSphere();
// Actual wetted portion of the vertical wall face.
wettedFace.scale.set(1, H, 1);
wettedFace.position.y = H / 2;
// Local pressure arrows: depth is measured downward from the free surface.
pressureArrows.forEach((arrow, index) => {
const depth = H * (index + 1) / (pressureArrowCount + 1);
const pressureKPa = MODEL.rho * MODEL.g * depth / 1000;
const displayLength =
pressureKPa * MODEL.pressureScale;
arrow.group.position.set(
WALL_LEFT + 0.01,
depth,
0.10
);
arrow.setLength(displayLength);
});
// A few pressure labels keep the local meaning explicit without clutter.
pressureLabelIndices.forEach((arrowIndex, labelIndex) => {
const depth = H * (arrowIndex + 1) / (pressureArrowCount + 1);
const pressureKPa = MODEL.rho * MODEL.g * depth / 1000;
pressureLabels[labelIndex].update(
`p = ${pressureKPa.toFixed(1)} kPa`
);
setLabelPosition(
pressureLabels[labelIndex],
WALL_LEFT - 0.12,
depth + 0.24,
0.29
);
});
// The separate gold arrow represents total force, not local pressure.
const resultantDisplayLength =
resultantKN * MODEL.forceScale;
resultantArrow.group.position.set(
WALL_LEFT + 0.015,
forceHeight,
0.24
);
resultantArrow.setLength(resultantDisplayLength);
resultantLabel.update(
`F_R = ${resultantKN.toFixed(1)} kN`
);
setLabelPosition(
resultantLabel,
WALL_LEFT + resultantDisplayLength * 0.53,
forceHeight + 0.47,
0.34
);
// Depth bracket from the free surface to the middle pressure arrow.
const selectedDepth = H * 0.5;
const bracketX = WALL_LEFT - 0.72;
depthBracket.geometry.dispose();
depthBracket.geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(bracketX, H, 0.24),
new THREE.Vector3(bracketX, selectedDepth, 0.24)
]);
depthBracket.computeLineDistances();
depthBracketCaps.geometry.dispose();
depthBracketCaps.geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(bracketX - 0.10, H, 0.24),
new THREE.Vector3(bracketX + 0.10, H, 0.24),
new THREE.Vector3(bracketX - 0.10, selectedDepth, 0.24),
new THREE.Vector3(bracketX + 0.10, selectedDepth, 0.24)
]);
depthLabel.update(`h = ${selectedDepth.toFixed(2)} m`);
setLabelPosition(
depthLabel,
bracketX - 0.24,
(H + selectedDepth) / 2,
0.31
);
// World-space labels.
freeSurfaceLabel.update(
`flat free surface · H = ${H.toFixed(2)} m`
);
setLabelPosition(
freeSurfaceLabel,
WATER_LEFT + 2.15,
H + 0.53,
0.16
);
setLabelPosition(
wettedFaceLabel,
WATER_LEFT + 2.8,
Math.max(0.85, H * 0.42),
0.18
);
setLabelPosition(
wallLabel,
0.08,
MODEL.wallHeight + 0.40,
0.10
);
setLabelPosition(
sectionLabel,
WATER_LEFT + 0.85,
-0.30,
0.18
);
}
levelSlider.addEventListener("input", updateModel);
updateModel();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```