Prompt specification
Build or customize the Three.js 3D scene "Beam parameter exploration model" 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: Beam parameter exploration model
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/beam-parameter-exploration-model-x1376
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring elastic bending of beams. Allow length, thickness, and load changes within small-deflection limits; display when assumptions are exceeded and avoid interpreting the demonstration as structural certification. Low-poly.
Working Three.js Starter (beam-parameter-exploration-model-x1376):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Elastic Beam Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 23, 40, 0.86);
--border: rgba(151, 190, 220, 0.18);
--text: #eaf4ff;
--muted: #9eb2c8;
--accent: #55d6be;
--warning: #ffb45b;
--danger: #ff786d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#viewport canvas {
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(13px);
-webkit-backdrop-filter: blur(13px);
}
#hud {
top: 16px;
left: 16px;
width: 330px;
padding: 17px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 1.55rem;
line-height: 1.15;
}
.subtitle {
margin: 8px 0 14px;
color: var(--muted);
font-size: 0.82rem;
line-height: 1.45;
}
.formula {
margin-bottom: 14px;
padding: 9px 10px;
border: 1px solid rgba(85, 214, 190, 0.16);
border-radius: 9px;
background: rgba(85, 214, 190, 0.055);
color: #c8eee7;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.76rem;
line-height: 1.5;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 61px;
padding: 9px;
border: 1px solid rgba(151, 190, 220, 0.12);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 0.68rem;
line-height: 1.2;
}
.metric-value {
display: block;
font-size: 0.96rem;
font-weight: 720;
font-variant-numeric: tabular-nums;
}
.status {
margin-top: 12px;
padding: 11px;
border: 1px solid rgba(85, 214, 190, 0.25);
border-radius: 10px;
background: rgba(85, 214, 190, 0.055);
}
.status.warn {
border-color: rgba(255, 116, 96, 0.52);
background: rgba(255, 116, 96, 0.09);
}
.status-title {
display: flex;
align-items: center;
gap: 8px;
color: var(--accent);
font-size: 0.76rem;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.status.warn .status-title {
color: var(--danger);
}
.status-icon {
display: inline-grid;
width: 19px;
height: 19px;
place-items: center;
border: 1px solid currentColor;
border-radius: 50%;
font-size: 0.72rem;
}
#statusList {
margin: 9px 0 0;
padding-left: 18px;
color: #c3d2df;
font-size: 0.72rem;
line-height: 1.45;
}
#statusList li + li {
margin-top: 5px;
}
#controls {
top: 16px;
right: 16px;
width: 320px;
padding: 17px;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.control-heading h2 {
margin: 0;
font-size: 0.98rem;
}
button {
border: 1px solid rgba(151, 190, 220, 0.25);
border-radius: 8px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.05);
color: var(--text);
font: inherit;
font-size: 0.72rem;
cursor: pointer;
}
button:hover {
border-color: var(--accent);
background: rgba(85, 214, 190, 0.09);
}
.control {
margin-top: 15px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 0.8rem;
}
.control-label span:first-child {
color: #dbe9f5;
font-weight: 650;
}
output {
color: var(--accent);
font-weight: 760;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #70869e;
font-size: 0.64rem;
}
.model-note {
margin-top: 16px;
padding-top: 13px;
border-top: 1px solid rgba(151, 190, 220, 0.12);
color: var(--muted);
font-size: 0.71rem;
line-height: 1.5;
}
.model-note strong {
color: #d4e4f1;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(151, 190, 220, 0.22);
border-radius: 7px;
background: rgba(7, 17, 31, 0.82);
color: #e8f3fc;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.22);
font-size: 0.69rem;
font-weight: 700;
white-space: nowrap;
}
#loadLabel {
border-color: rgba(255, 120, 109, 0.45);
color: #ffaaa2;
}
#help {
position: fixed;
right: 18px;
bottom: 82px;
z-index: 6;
color: rgba(207, 225, 239, 0.68);
font-size: 0.69rem;
pointer-events: none;
text-shadow: 0 1px 8px #000;
}
#disclaimer {
position: fixed;
right: 16px;
bottom: 14px;
left: 16px;
z-index: 12;
padding: 10px 14px;
border: 1px solid rgba(255, 180, 91, 0.28);
border-radius: 10px;
background: rgba(31, 22, 14, 0.9);
color: #f0d4ad;
font-size: 0.72rem;
line-height: 1.42;
text-align: center;
backdrop-filter: blur(10px);
}
#disclaimer strong {
color: #ffdca9;
}
@media (max-width: 760px) {
#hud {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 36vh;
padding: 13px;
overflow: auto;
}
h1 {
font-size: 1.25rem;
}
.formula,
.metric:nth-child(n + 5) {
display: none;
}
.metrics {
grid-template-columns: repeat(4, 1fr);
}
.metric {
min-height: 51px;
padding: 7px;
}
.metric-label {
font-size: 0.58rem;
}
.metric-value {
font-size: 0.76rem;
}
#controls {
top: auto;
right: 10px;
bottom: 82px;
width: calc(100vw - 20px);
max-height: 43vh;
padding: 13px;
overflow: auto;
}
.control {
margin-top: 11px;
}
.model-note {
margin-top: 12px;
}
#help {
display: none;
}
#disclaimer {
right: 8px;
bottom: 8px;
left: 8px;
padding: 8px 10px;
font-size: 0.65rem;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels">
<div id="loadLabel" class="world-label">0.0 kN ↓</div>
<div id="supportLabel" class="world-label">Fixed support</div>
</div>
<section id="hud" class="panel">
<div class="eyebrow">Elastic response study</div>
<h1>Elastic Beam Lab</h1>
<p class="subtitle">
Low-poly Euler–Bernoulli cantilever with a point load at the free end.
Dimensions are modeled in true units.
</p>
<div class="formula">
δ = PL³ / 3EI · θ = PL² / 2EI<br>
Square section: I = t⁴ / 12
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Unscaled tip deflection</span>
<span id="deflectionValue" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Deflection / length</span>
<span id="ratioValue" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Reference bending stress</span>
<span id="stressValue" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Extreme-fiber strain</span>
<span id="strainValue" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Free-end moment</span>
<span id="momentValue" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Visual-only magnification</span>
<span id="gainValue" class="metric-value">—</span>
</div>
</div>
<div id="statusBox" class="status" aria-live="polite">
<div class="status-title">
<span id="statusIcon" class="status-icon">i</span>
<span id="statusTitle">Screening assumptions met</span>
</div>
<ul id="statusList"></ul>
</div>
</section>
<section id="controls" class="panel">
<div class="control-heading">
<h2>Model parameters</h2>
<button id="resetView" type="button">Reset view</button>
</div>
<div class="control">
<label class="control-label" for="lengthInput">
<span>Beam length, L</span>
<output id="lengthValue" for="lengthInput">3.00 m</output>
</label>
<input id="lengthInput" type="range" min="0.5" max="5" step="0.1" value="3">
<div class="range-ends"><span>0.5 m</span><span>5.0 m</span></div>
</div>
<div class="control">
<label class="control-label" for="thicknessInput">
<span>Square-section thickness, t</span>
<output id="thicknessValue" for="thicknessInput">80 mm</output>
</label>
<input id="thicknessInput" type="range" min="40" max="200" step="1" value="80">
<div class="range-ends"><span>40 mm</span><span>200 mm</span></div>
</div>
<div class="control">
<label class="control-label" for="loadInput">
<span>Free-end load, P</span>
<output id="loadValue" for="loadInput">8.0 kN</output>
</label>
<input id="loadInput" type="range" min="0" max="30" step="0.5" value="8">
<div class="range-ends"><span>0 kN</span><span>30 kN</span></div>
</div>
<div class="model-note">
<strong>Reference material:</strong> E = 200 GPa, for illustration only.
Small-deflection screen: δ/L ≤ 5%. Slenderness screen: L/t ≥ 10.
Conservative strain-linearity proxy: ε ≤ 0.2%.
<br><br>
The displayed curve may be magnified. Numerical readouts are never magnified.
</div>
</section>
<div id="help">Drag to orbit · Wheel to zoom · R to reset</div>
<div id="disclaimer">
<strong>Educational visualization only — not structural certification.</strong>
This idealization is not a structural analysis, design, safety assessment, or capacity check.
Real beams require validated material data, boundary conditions, local effects, applicable codes,
and qualified professional review.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model constants
// -------------------------------------------------------------------------
const E = 200e9; // Reference elastic modulus, Pa
const SEGMENTS = 24; // Deliberately low-poly beam
const SMALL_DEFLECTION_LIMIT = 0.05;
const SLENDERNESS_LIMIT = 10;
const STRAIN_SCREEN_LIMIT = 0.002;
const viewport = document.getElementById("viewport");
const lengthInput = document.getElementById("lengthInput");
const thicknessInput = document.getElementById("thicknessInput");
const loadInput = document.getElementById("loadInput");
const lengthValue = document.getElementById("lengthValue");
const thicknessValue = document.getElementById("thicknessValue");
const loadValue = document.getElementById("loadValue");
const deflectionValue = document.getElementById("deflectionValue");
const ratioValue = document.getElementById("ratioValue");
const stressValue = document.getElementById("stressValue");
const strainValue = document.getElementById("strainValue");
const momentValue = document.getElementById("momentValue");
const gainValue = document.getElementById("gainValue");
const statusBox = document.getElementById("statusBox");
const statusIcon = document.getElementById("statusIcon");
const statusTitle = document.getElementById("statusTitle");
const statusList = document.getElementById("statusList");
const loadLabel = document.getElementById("loadLabel");
const supportLabel = document.getElementById("supportLabel");
let L = Number(lengthInput.value);
let t = Number(thicknessInput.value) / 1000;
let P = Number(loadInput.value) * 1000;
let visualTip = 0;
let visualGain = 1;
let supportHeight = 0.4;
let arrowLength = 0.5;
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.05;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-5, 5, 5, -5, 0.01, 100);
camera.position.set(10, 5, 8);
const hemisphere = new THREE.HemisphereLight(0xc3ebff, 0x102038, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.6);
keyLight.position.set(4, 8, 6);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4bdcff, 1.25);
rimLight.position.set(-5, 3, -6);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Low-poly beam geometry
// -------------------------------------------------------------------------
const ringCount = SEGMENTS + 1;
const beamPositions = new Float32Array(ringCount * 4 * 3);
const beamIndices = [];
for (let i = 0; i < SEGMENTS; i++) {
const a = i * 4;
const b = (i + 1) * 4;
// Top, +Z side, bottom, -Z side.
beamIndices.push(
a + 0, a + 1, b + 1, a + 0, b + 1, b + 0,
a + 1, b + 1, b + 2, a + 1, b + 2, a + 2,
a + 2, a + 3, b + 3, a + 2, b + 3, b + 2,
a + 3, b + 3, b + 0, a + 3, b + 0, a + 0
);
}
const end = SEGMENTS * 4;
beamIndices.push(
0, 3, 2, 0, 2, 1,
end + 0, end + 1, end + 2,
end + 0, end + 2, end + 3
);
const beamGeometry = new THREE.BufferGeometry();
beamGeometry.setAttribute(
"position",
new THREE.BufferAttribute(beamPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
beamGeometry.setIndex(beamIndices);
const beamMaterial = new THREE.MeshStandardMaterial({
color: 0x55d6be,
roughness: 0.52,
metalness: 0.18,
flatShading: true,
side: THREE.DoubleSide
});
const beamMesh = new THREE.Mesh(beamGeometry, beamMaterial);
beamMesh.frustumCulled = false;
scene.add(beamMesh);
// Deflected centerline.
const centerPositions = new Float32Array((SEGMENTS + 1) * 3);
const centerGeometry = new THREE.BufferGeometry();
centerGeometry.setAttribute(
"position",
new THREE.BufferAttribute(centerPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
const centerLine = new THREE.Line(
centerGeometry,
new THREE.LineBasicMaterial({ color: 0xf6dc72 })
);
centerLine.frustumCulled = false;
scene.add(centerLine);
// Undeformed datum.
const datumGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(L, 0, 0)
]);
const datumLine = new THREE.Line(
datumGeometry,
new THREE.LineDashedMaterial({
color: 0x8499ad,
dashSize: 0.08,
gapSize: 0.06,
transparent: true,
opacity: 0.55
})
);
datumLine.computeLineDistances();
scene.add(datumLine);
// -------------------------------------------------------------------------
// Support, grid, and load arrow
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const wall = new THREE.Mesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0x49647c,
roughness: 0.8,
metalness: 0.12,
flatShading: true
})
);
scene.add(wall);
const jawMaterial = new THREE.MeshStandardMaterial({
color: 0x91a7ba,
roughness: 0.66,
metalness: 0.2,
flatShading: true
});
const upperJaw = new THREE.Mesh(unitBox, jawMaterial);
const lowerJaw = new THREE.Mesh(unitBox, jawMaterial);
scene.add(upperJaw, lowerJaw);
const grid = new THREE.GridHelper(1, 16, 0x32617c, 0x183249);
grid.material.transparent = true;
grid.material.opacity = 0.64;
grid.material.depthWrite = false;
scene.add(grid);
const loadArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(),
0.5,
0xff665c,
0.14,
0.08
);
scene.add(loadArrow);
// -------------------------------------------------------------------------
// Direct camera controls: no examples/addons are imported.
// -------------------------------------------------------------------------
let cameraYaw = 0.48;
let cameraPitch = 0.30;
let cameraZoom = 1;
let baseHalfHeight = 2;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCameraProjection() {
const aspect = window.innerWidth / Math.max(window.innerHeight, 1);
const verticalNeed = Math.max(
0.95,
L * 0.68,
Math.abs(visualTip) * 1.5
);
const horizontalNeed = L * 1.38 + 0.4;
baseHalfHeight = Math.max(
verticalNeed * 0.5,
horizontalNeed / (2 * aspect)
);
camera.left = -baseHalfHeight * aspect;
camera.right = baseHalfHeight * aspect;
camera.top = baseHalfHeight;
camera.bottom = -baseHalfHeight;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function updateCamera() {
const targetY = -Math.min(
L * 0.6,
Math.max(L * 0.065, Math.abs(visualTip) * 0.25)
);
const target = new THREE.Vector3(L * 0.48, targetY, 0);
const distance = 20;
camera.position.set(
target.x + distance * Math.cos(cameraPitch) * Math.cos(cameraYaw),
target.y + distance * Math.sin(cameraPitch),
target.z + distance * Math.cos(cameraPitch) * Math.sin(cameraYaw)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraYaw = 0.48;
cameraPitch = 0.30;
cameraZoom = 1;
updateCameraProjection();
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.004,
-0.18,
1.12
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.55,
4.5
);
updateCameraProjection();
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetView").addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetCamera();
});
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCameraProjection();
updateCamera();
});
// -------------------------------------------------------------------------
// Euler–Bernoulli calculations and geometry update
// -------------------------------------------------------------------------
function updateBeamGeometry() {
const I = Math.pow(t, 4) / 12;
const EI = E * I;
const tipDeflection = P * Math.pow(L, 3) / (3 * EI);
const tipSlope = P * Math.pow(L, 2) / (2 * EI);
const ratio = L > 0 ? tipDeflection / L : 0;
// Magnify only modest physical deflections so that the response is visible.
// Invalid large-deflection cases are shown at 1× rather than exaggerated.
visualGain = 1;
if (P > 0 && ratio > 0 && ratio < 0.10) {
visualGain = Math.min(250, 0.10 / ratio);
}
visualTip = -tipDeflection * visualGain;
const curvatureFactor = P / EI;
for (let i = 0; i <= SEGMENTS; i++) {
const x = L * i / SEGMENTS;
// Cantilever with a point load at x = L.
const physicalY = -curvatureFactor * (
L * x * x * 0.5 - Math.pow(x, 3) / 6
);
const physicalSlope = -curvatureFactor * (
L * x - x * x * 0.5
);
const y = physicalY * visualGain;
const slope = physicalSlope * visualGain;
const theta = Math.atan(slope);
// Normal to the local beam axis.
const nx = -Math.sin(theta);
const ny = Math.cos(theta);
const halfThickness = t * 0.5;
const halfWidth = t * 0.5;
const corners = [
[x + nx * halfThickness, y + ny * halfThickness, -halfWidth],
[x + nx * halfThickness, y + ny * halfThickness, halfWidth],
[x - nx * halfThickness, y - ny * halfThickness, halfWidth],
[x - nx * halfThickness, y - ny * halfThickness, -halfWidth]
];
for (let c = 0; c < 4; c++) {
const vertex = (i * 4 + c) * 3;
beamPositions[vertex] = corners[c][0];
beamPositions[vertex + 1] = corners[c][1];
beamPositions[vertex + 2] = corners[c][2];
}
centerPositions[i * 3] = x;
centerPositions[i * 3 + 1] = y;
centerPositions[i * 3 + 2] = 0;
}
beamGeometry.attributes.position.needsUpdate = true;
beamGeometry.computeVertexNormals();
beamGeometry.computeBoundingSphere();
centerGeometry.attributes.position.needsUpdate = true;
centerGeometry.computeBoundingSphere();
const datumPoints = [
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(L, 0, 0)
];
datumGeometry.setFromPoints(datumPoints);
datumLine.computeLineDistances();
return {
I,
tipDeflection,
tipSlope,
ratio,
maxMoment: P * L,
stress: P * L * (t * 0.5) / I,
strain: (P * L * (t * 0.5) / I) / E
};
}
function updateSupportAndArrow() {
supportHeight = Math.max(0.34, L * 0.12);
const supportDepth = Math.max(0.24, t * 1.7 + 0.10);
wall.scale.set(0.11, supportHeight, supportDepth);
wall.position.set(-0.065, 0, 0);
upperJaw.scale.set(0.18, 0.065, supportDepth * 0.82);
lowerJaw.scale.copy(upperJaw.scale);
upperJaw.position.set(0.055, t * 0.5 + 0.0325, 0);
lowerJaw.position.set(0.055, -t * 0.5 - 0.0325, 0);
const gridSize = Math.max(2.5, L * 1.8);
grid.scale.set(gridSize, 1, gridSize);
grid.position.set(L * 0.5, -L * 0.28, 0);
arrowLength = Math.max(0.38, L * 0.13);
const headLength = Math.min(
arrowLength * 0.36,
Math.max(0.10, t * 1.25)
);
const headWidth = Math.max(0.055, t * 0.85);
loadArrow.position.set(
L,
visualTip + t * 0.5 + arrowLength,
0
);
loadArrow.setDirection(new THREE.Vector3(0, -1, 0));
loadArrow.setLength(arrowLength, headLength, headWidth);
loadArrow.visible = P > 0;
}
function formatGain(value) {
if (value >= 100) return `${value.toFixed(0)}×`;
if (value >= 10) return `${value.toFixed(1)}×`;
return `${value.toFixed(2)}×`;
}
function setStatus(failures) {
statusBox.classList.toggle("warn", failures.length > 0);
statusBox.classList.toggle("ok", failures.length === 0);
statusIcon.textContent = failures.length > 0 ? "!" : "i";
statusTitle.textContent = failures.length > 0
? "Model assumptions exceeded"
: "Screening assumptions met";
statusList.replaceChildren();
if (failures.length === 0) {
const item = document.createElement("li");
item.textContent =
"Selected numerical screens are met; real-world failure modes remain unverified.";
statusList.appendChild(item);
} else {
for (const message of failures) {
const item = document.createElement("li");
item.textContent = message;
statusList.appendChild(item);
}
}
}
function updateScene(resetZoom = false) {
L = Number(lengthInput.value);
t = Number(thicknessInput.value) / 1000;
P = Number(loadInput.value) * 1000;
const result = updateBeamGeometry();
updateSupportAndArrow();
lengthValue.textContent = `${L.toFixed(2)} m`;
thicknessValue.textContent = `${Math.round(t * 1000)} mm`;
loadValue.textContent = `${(P / 1000).toFixed(1)} kN`;
deflectionValue.textContent = `${(result.tipDeflection * 1000).toFixed(1)} mm`;
ratioValue.textContent = `${(result.ratio * 100).toFixed(2)} %`;
stressValue.textContent = `${(result.stress / 1e6).toFixed(1)} MPa`;
strainValue.textContent = `${(result.strain * 100).toFixed(3)} %`;
momentValue.textContent = `${(result.maxMoment / 1000).toFixed(1)} kN·m`;
gainValue.textContent = formatGain(visualGain);
loadLabel.textContent = `${(P / 1000).toFixed(1)} kN ↓`;
const failures = [];
if (result.ratio > SMALL_DEFLECTION_LIMIT + 1e-9) {
failures.push(
`Small-deflection screen exceeded: δ/L = ${(result.ratio * 100).toFixed(1)}% > 5%.`
);
}
if (L / t < SLENDERNESS_LIMIT) {
failures.push(
`Slenderness screen exceeded: L/t = ${(L / t).toFixed(1)} < 10.`
);
}
if (result.strain > STRAIN_SCREEN_LIMIT + 1e-12) {
failures.push(
`Strain-linearity proxy exceeded: ε = ${(result.strain * 100).toFixed(3)}% > 0.2%.`
);
}
setStatus(failures);
if (resetZoom) cameraZoom = 1;
updateCameraProjection();
updateCamera();
}
// -------------------------------------------------------------------------
// Project HTML labels into the 3D view.
// -------------------------------------------------------------------------
function positionWorldLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
positionWorldLabel(
loadLabel,
new THREE.Vector3(
L,
visualTip + t * 0.5 + arrowLength * 0.55,
0
)
);
positionWorldLabel(
supportLabel,
new THREE.Vector3(-0.12, supportHeight * 0.72, 0)
);
}
// -------------------------------------------------------------------------
// Events and render loop
// -------------------------------------------------------------------------
lengthInput.addEventListener("input", () => updateScene(true));
thicknessInput.addEventListener("input", () => updateScene());
loadInput.addEventListener("input", () => updateScene());
updateScene(true);
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```