Prompt specification
Build or customize the Three.js 3D scene "Cantilever strips of different thickness" 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: Cantilever strips of different thickness
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cantilever-strips-of-different-thickness-x1373
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing elastic bending of beams. Build two clamped beams of equal length and material with different thicknesses; show small-deflection shapes under a stated linear elastic approximation. Low-poly.
Working Three.js Starter (cantilever-strips-of-different-thickness-x1373):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elastic Bending of Beams</title>
<style>
:root {
color-scheme: dark;
--orange: #ff835f;
--cyan: #49d8d0;
--yellow: #ffd166;
--panel: rgba(13, 20, 35, 0.82);
--border: rgba(255, 255, 255, 0.12);
--muted: #aebbd0;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09101d;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: absolute;
z-index: 10;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.title-panel {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 21px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--yellow);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #f7f9fc;
font-size: clamp(21px, 3vw, 29px);
line-height: 1.12;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.data-panel {
right: 22px;
bottom: 22px;
width: min(440px, calc(100vw - 44px));
padding: 16px 18px;
font-size: 12px;
}
.data-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 16px;
margin-bottom: 12px;
}
.datum {
display: flex;
justify-content: space-between;
gap: 14px;
padding-bottom: 5px;
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.datum span {
color: var(--muted);
}
.datum b {
color: #f4f7fb;
font-variant-numeric: tabular-nums;
}
.equation {
padding: 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: #f4f7fb;
font-family: "Cambria Math", "Times New Roman", serif;
font-size: 14px;
text-align: center;
}
.note {
margin-top: 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.legend {
position: absolute;
z-index: 10;
bottom: 24px;
left: 22px;
display: flex;
gap: 16px;
align-items: center;
color: var(--muted);
font-size: 12px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 18px;
height: 5px;
border-radius: 5px;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.orange {
color: var(--orange);
}
.cyan {
color: var(--cyan);
}
.gray {
color: #93a4be;
}
#controls-hint {
position: absolute;
z-index: 10;
top: 24px;
right: 24px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(13, 20, 35, 0.7);
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
#reset-camera {
position: absolute;
z-index: 20;
top: 62px;
right: 24px;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(13, 20, 35, 0.86);
color: #eaf0f8;
font: inherit;
font-size: 11px;
cursor: pointer;
}
#reset-camera:hover {
border-color: rgba(255, 255, 255, 0.3);
background: rgba(27, 39, 61, 0.94);
}
.scene-label {
position: absolute;
z-index: 6;
top: 0;
left: 0;
display: none;
min-width: 128px;
padding: 8px 10px;
border: 1px solid var(--border);
border-left: 3px solid currentColor;
border-radius: 7px;
background: rgba(8, 14, 25, 0.84);
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
color: #f4f7fb;
font-size: 11px;
line-height: 1.35;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.scene-label strong {
display: block;
color: currentColor;
font-size: 12px;
}
.scene-label span {
color: #c1ccdc;
}
.tip-label {
min-width: 110px;
text-align: center;
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
max-width: 85%;
}
.data-panel {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px 14px;
}
.legend {
display: none;
}
#controls-hint {
display: none;
}
#reset-camera {
top: auto;
right: 12px;
bottom: 246px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section class="panel title-panel">
<div class="eyebrow">Linear Elastic · Euler–Bernoulli</div>
<h1>Elastic bending of clamped beams</h1>
<p class="subtitle">
Two cantilever beams with equal length, width, material, and tip load.
Only their rectangular cross-section thickness differs.
</p>
</section>
<section class="panel data-panel">
<div class="data-grid">
<div class="datum"><span>Length L</span><b>5.00 m</b></div>
<div class="datum"><span>Width b</span><b>0.55 m</b></div>
<div class="datum"><span>Modulus E</span><b>2.0 GPa</b></div>
<div class="datum"><span>Tip load P</span><b>1.5 kN</b></div>
<div class="datum"><span>Beam A thickness</span><b>160 mm</b></div>
<div class="datum"><span>Beam B thickness</span><b>240 mm</b></div>
<div class="datum"><span>A tip deflection</span><b>166.4 mm</b></div>
<div class="datum"><span>B tip deflection</span><b>49.3 mm</b></div>
</div>
<div class="equation">
δ(x) = P x²(3L − x)/(6EI), I = bh³/12
</div>
<div class="note">
Small-deflection, linear-elastic approximation: shear deformation and
geometric nonlinearity are neglected. Geometry is displayed at true 1:1
scale. The thinner beam is 3.38× more flexible because stiffness varies
with h³.
</div>
</section>
<div class="legend">
<div class="legend-item orange">
<span class="swatch"></span><span>Beam A · t = 160 mm</span>
</div>
<div class="legend-item cyan">
<span class="swatch"></span><span>Beam B · t = 240 mm</span>
</div>
<div class="legend-item gray">
<span class="swatch"></span><span>Undeformed centerline</span>
</div>
</div>
<div id="controls-hint">Drag to orbit · wheel to zoom</div>
<button id="reset-camera" type="button">Reset camera</button>
<div id="label-a" class="scene-label orange">
<strong>Beam A</strong>
<span>t = 160 mm</span>
</div>
<div id="label-b" class="scene-label cyan">
<strong>Beam B</strong>
<span>t = 240 mm</span>
</div>
<div id="tip-a" class="scene-label orange tip-label">
<strong>δ = 166.4 mm</strong>
<span>Free end</span>
</div>
<div id="tip-b" class="scene-label cyan tip-label">
<strong>δ = 49.3 mm</strong>
<span>Free end</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model parameters
// -------------------------------------------------------------------------
const L = 5.0; // Beam length, m
const b = 0.55; // Common cross-section width, m
const E = 2.0e9; // Illustrative polymer modulus, Pa
const P = 1500; // Equal downward tip load, N
const thicknessA = 0.16; // m
const thicknessB = 0.24; // m
const zA = -1.18;
const zB = 1.18;
const momentA = b * Math.pow(thicknessA, 3) / 12;
const momentB = b * Math.pow(thicknessB, 3) / 12;
const rigidityA = E * momentA;
const rigidityB = E * momentB;
const tipA = P * Math.pow(L, 3) / (3 * rigidityA);
const tipB = P * Math.pow(L, 3) / (3 * rigidityB);
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const app = document.getElementById("app");
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of two elastically bending cantilever beams"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09101d);
scene.fog = new THREE.Fog(0x09101d, 14, 29);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(
0xcfe4ff,
0x18202d,
1.55
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(3.5, 8.0, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x70a7ff, 1.5);
rimLight.position.set(-4, 3, -6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 22),
new THREE.MeshStandardMaterial({
color: 0x0d1726,
roughness: 0.93,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.08;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
24,
48,
0x38506d,
0x1c2b3e
);
grid.position.y = -1.065;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
// -------------------------------------------------------------------------
// Euler–Bernoulli beam geometry
// -------------------------------------------------------------------------
function beamDeflection(x, rigidity) {
return P * x * x * (3 * L - x) / (6 * rigidity);
}
function beamSlope(x, rigidity) {
// dy/dx for the downward displacement convention.
return -P * x * (2 * L - x) / (2 * rigidity);
}
function createBeamGeometry(thickness, rigidity, z, segments = 30) {
const positions = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const x = (i / segments) * L;
const centerY = -beamDeflection(x, rigidity);
const slope = beamSlope(x, rigidity);
// Cross-sections remain approximately normal to the deformed centerline.
const normal = new THREE.Vector2(-slope, 1).normalize();
const halfHeight = thickness / 2;
const halfWidth = b / 2;
const corners = [
{
x: x + normal.x * halfHeight,
y: centerY + normal.y * halfHeight,
z: z - halfWidth
},
{
x: x - normal.x * halfHeight,
y: centerY - normal.y * halfHeight,
z: z - halfWidth
},
{
x: x - normal.x * halfHeight,
y: centerY - normal.y * halfHeight,
z: z + halfWidth
},
{
x: x + normal.x * halfHeight,
y: centerY + normal.y * halfHeight,
z: z + halfWidth
}
];
for (const corner of corners) {
positions.push(corner.x, corner.y, corner.z);
}
}
for (let i = 0; i < segments; i++) {
for (let j = 0; j < 4; j++) {
const next = (j + 1) % 4;
const a = i * 4 + j;
const bb = (i + 1) * 4 + j;
const c = (i + 1) * 4 + next;
const d = i * 4 + next;
indices.push(a, bb, c, a, c, d);
}
}
// Clamped end cap.
indices.push(0, 1, 2, 0, 2, 3);
// Free end cap.
const end = segments * 4;
indices.push(end, end + 2, end + 1, end, end + 3, end + 2);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const beamMaterialA = new THREE.MeshStandardMaterial({
color: 0xff835f,
roughness: 0.48,
metalness: 0.16,
flatShading: true
});
const beamMaterialB = new THREE.MeshStandardMaterial({
color: 0x49d8d0,
roughness: 0.46,
metalness: 0.18,
flatShading: true
});
const clampMaterial = new THREE.MeshStandardMaterial({
color: 0x34445c,
roughness: 0.36,
metalness: 0.72,
flatShading: true
});
const jawMaterial = new THREE.MeshStandardMaterial({
color: 0x1a273a,
roughness: 0.32,
metalness: 0.78,
flatShading: true
});
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0x8b9bb2,
roughness: 0.25,
metalness: 0.9,
flatShading: true
});
const centerlineMaterial = new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.58,
depthTest: false
});
const baselineMaterial = new THREE.LineDashedMaterial({
color: 0x92a4bf,
dashSize: 0.15,
gapSize: 0.10,
transparent: true,
opacity: 0.55,
depthTest: false
});
function createClamp(z) {
const group = new THREE.Group();
const wall = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 1.35, 0.90),
clampMaterial
);
wall.position.set(-0.21, -0.30, z);
wall.castShadow = true;
wall.receiveShadow = true;
group.add(wall);
const base = new THREE.Mesh(
new THREE.BoxGeometry(0.76, 0.12, 1.13),
jawMaterial
);
base.position.set(-0.24, -0.965, z);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const boltGeometry = new THREE.CylinderGeometry(
0.042,
0.042,
0.065,
8
);
for (const y of [-0.56, -0.08]) {
const bolt = new THREE.Mesh(boltGeometry, boltMaterial);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(-0.20, y, z + 0.475);
bolt.castShadow = true;
group.add(bolt);
}
scene.add(group);
}
function createBeam({
name,
thickness,
rigidity,
z,
material,
centerlineColor
}) {
const geometry = createBeamGeometry(thickness, rigidity, z);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.name = name;
scene.add(mesh);
// Dashed undeformed reference centerline.
const baseline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, z),
new THREE.Vector3(L, 0, z)
]),
baselineMaterial
);
baseline.computeLineDistances();
baseline.renderOrder = 7;
scene.add(baseline);
// Visible deformed centerline, drawn through the low-poly solid.
const centerPoints = [];
for (let i = 0; i <= 60; i++) {
const x = (i / 60) * L;
centerPoints.push(
new THREE.Vector3(x, -beamDeflection(x, rigidity), z)
);
}
const centerline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(centerPoints),
centerlineMaterial.clone()
);
centerline.material.color.set(centerlineColor);
centerline.renderOrder = 8;
scene.add(centerline);
// Vertical tip-deflection measurement.
const tipY = -beamDeflection(L, rigidity);
const measurement = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(L, 0, z),
new THREE.Vector3(L, tipY, z)
]),
new THREE.LineDashedMaterial({
color: centerlineColor,
dashSize: 0.07,
gapSize: 0.05,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
measurement.computeLineDistances();
measurement.renderOrder = 9;
scene.add(measurement);
const tipMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 10, 7),
new THREE.MeshBasicMaterial({
color: centerlineColor,
depthTest: false
})
);
tipMarker.position.set(L, tipY, z);
tipMarker.renderOrder = 10;
scene.add(tipMarker);
// Equal downward tip load.
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(L, tipY + 1.10, z),
1.10,
0xffd166,
0.22,
0.13
);
arrow.line.material.depthTest = false;
arrow.cone.material.depthTest = false;
arrow.line.renderOrder = 10;
arrow.cone.renderOrder = 10;
scene.add(arrow);
createClamp(z);
}
createBeam({
name: "Beam A",
thickness: thicknessA,
rigidity: rigidityA,
z: zA,
material: beamMaterialA,
centerlineColor: 0xffb097
});
createBeam({
name: "Beam B",
thickness: thicknessB,
rigidity: rigidityB,
z: zB,
material: beamMaterialB,
centerlineColor: 0xa0fff8
});
// -------------------------------------------------------------------------
// Direct camera controls: no addons or external controls are used.
// -------------------------------------------------------------------------
const initialCamera = {
radius: 11.6,
theta: 0.56,
phi: 1.18,
target: new THREE.Vector3(2.45, -0.20, 0)
};
const desired = {
radius: initialCamera.radius,
theta: initialCamera.theta,
phi: initialCamera.phi
};
const current = {
radius: desired.radius,
theta: desired.theta,
phi: desired.phi
};
const cameraTarget = initialCamera.target.clone();
let dragging = false;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.34,
1.49
);
previousX = event.clientX;
previousY = event.clientY;
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
6.2,
20
);
},
{ passive: false }
);
document.getElementById("reset-camera").addEventListener("click", () => {
desired.radius = initialCamera.radius;
desired.theta = initialCamera.theta;
desired.phi = initialCamera.phi;
cameraTarget.copy(initialCamera.target);
});
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function updateCamera() {
current.radius += (desired.radius - current.radius) * 0.12;
current.theta += (desired.theta - current.theta) * 0.12;
current.phi += (desired.phi - current.phi) * 0.12;
spherical.set(
current.radius,
current.phi,
current.theta
);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelA = document.getElementById("label-a");
const labelB = document.getElementById("label-b");
const tipLabelA = document.getElementById("tip-a");
const tipLabelB = document.getElementById("tip-b");
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
projected.copy(worldPosition).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.transform =
`translate(${x + offsetX}px, ${y + offsetY}px) translate(-50%, -50%)`;
}
function updateLabels() {
placeLabel(
labelA,
new THREE.Vector3(1.65, 0.42, zA),
-10,
-10
);
placeLabel(
labelB,
new THREE.Vector3(1.65, 0.52, zB),
10,
-10
);
placeLabel(
tipLabelA,
new THREE.Vector3(L + 0.02, -tipA, zA),
58,
23
);
placeLabel(
tipLabelB,
new THREE.Vector3(L + 0.02, -tipB, zB),
58,
22
);
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```