Prompt specification
Build or customize the Three.js 3D scene "Equal-force unequal-arm 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: Equal-force unequal-arm comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/equal-force-unequal-arm-comparison-x1410
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a scene with two levers with the same force applied at different distances; visualize different torque magnitudes and label the idealized rigid-body assumption. Stylized solid forms.
Working Three.js Starter (equal-force-unequal-arm-comparison-x1410):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Same Force, Different Torque</title>
<style>
:root {
--ink: #172c43;
--muted: #647487;
--paper: #f8fafb;
--gold: #f5b942;
--coral: #f16c5d;
--teal: #27a8a0;
--blue: #5578d9;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe7eb;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
user-select: none;
filter: drop-shadow(0 5px 12px rgba(23, 44, 67, 0.1));
}
.case-label {
padding: 7px 12px;
border: 1px solid rgba(23, 44, 67, 0.12);
border-radius: 999px;
background: rgba(248, 250, 251, 0.84);
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
backdrop-filter: blur(8px);
}
.force-label {
padding: 8px 12px;
border: 1px solid rgba(245, 185, 66, 0.75);
border-radius: 10px;
background: #fff8e7;
color: #704900;
font-size: 13px;
font-weight: 850;
box-shadow: 0 7px 18px rgba(113, 78, 15, 0.12);
}
.distance-label {
padding: 5px 9px;
border-radius: 7px;
background: rgba(23, 44, 67, 0.86);
color: white;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
}
.torque-label {
min-width: 132px;
padding: 10px 13px;
border-left: 5px solid var(--accent, var(--coral));
border-radius: 10px;
background: rgba(248, 250, 251, 0.94);
color: var(--ink);
text-align: left;
box-shadow: 0 8px 22px rgba(23, 44, 67, 0.14);
}
.torque-label strong {
display: block;
font-size: 16px;
line-height: 1.1;
font-weight: 900;
}
.torque-label span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.gauge-label {
padding: 4px 8px;
border-radius: 999px;
background: rgba(23, 44, 67, 0.82);
color: white;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
}
.hud {
position: fixed;
z-index: 6;
pointer-events: none;
}
#intro {
top: 22px;
left: 24px;
width: 330px;
}
.eyebrow {
color: #4f6578;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
color: var(--ink);
font-size: clamp(28px, 3.1vw, 45px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 900;
}
#intro p {
max-width: 300px;
margin: 0;
color: #53687a;
font-size: 13px;
line-height: 1.5;
font-weight: 550;
}
#formula {
top: 22px;
right: 24px;
min-width: 210px;
padding: 14px 17px;
border: 1px solid rgba(23, 44, 67, 0.1);
border-radius: 16px;
background: rgba(248, 250, 251, 0.88);
box-shadow: 0 12px 30px rgba(23, 44, 67, 0.1);
backdrop-filter: blur(10px);
}
.equation {
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
line-height: 1;
font-style: italic;
font-weight: 700;
}
.formula-caption {
margin-top: 8px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
}
.legend {
display: flex;
gap: 13px;
margin-top: 11px;
color: #52687b;
font-size: 10px;
font-weight: 750;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.dot.force {
background: var(--gold);
}
.dot.torque {
background: var(--coral);
}
#assumption {
left: 50%;
bottom: 18px;
width: min(900px, calc(100% - 40px));
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 16px;
padding: 13px 18px;
border: 1px solid rgba(23, 44, 67, 0.13);
border-radius: 16px;
background: rgba(248, 250, 251, 0.92);
box-shadow: 0 12px 34px rgba(23, 44, 67, 0.13);
backdrop-filter: blur(10px);
}
.assumption-icon {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 38px;
height: 38px;
border-radius: 12px;
background: var(--ink);
color: white;
font-size: 18px;
font-weight: 900;
}
.assumption-copy {
min-width: 0;
}
.assumption-copy strong {
display: block;
color: var(--ink);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.assumption-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
font-weight: 550;
}
#hint {
right: 24px;
bottom: 106px;
color: rgba(23, 44, 67, 0.58);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 800px) {
#intro {
top: 14px;
left: 14px;
width: calc(100% - 28px);
}
#intro p,
#formula,
#hint,
.case-label {
display: none;
}
h1 {
max-width: 270px;
margin-bottom: 0;
font-size: 29px;
}
#assumption {
width: calc(100% - 24px);
bottom: 12px;
gap: 11px;
padding: 11px 13px;
}
.assumption-icon {
width: 32px;
height: 32px;
border-radius: 10px;
}
.assumption-copy strong {
font-size: 10px;
}
.assumption-copy span {
font-size: 9px;
}
.torque-label {
min-width: 110px;
padding: 8px 10px;
}
.torque-label strong {
font-size: 13px;
}
.force-label,
.distance-label,
.gauge-label {
transform: translate(-50%, -50%) scale(0.86);
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D comparison of two levers"></main>
<div id="labels" aria-hidden="true"></div>
<section id="intro" class="hud">
<div class="eyebrow">Mechanics / Lever Comparison</div>
<h1>Same force.<br />Different torque.</h1>
<p>
A 20 N force acts on each rigid lever. Doubling the perpendicular
distance from the fixed axis doubles the torque.
</p>
</section>
<aside id="formula" class="hud">
<div class="equation">τ = F × d<sub>⊥</sub></div>
<div class="formula-caption">Same force · different moment arm</div>
<div class="legend">
<span class="legend-item">
<span class="dot force"></span>
Applied force
</span>
<span class="legend-item">
<span class="dot torque"></span>
Resulting torque
</span>
</div>
</aside>
<div id="hint" class="hud">DRAG TO ORBIT · SCROLL TO ZOOM</div>
<section id="assumption" class="hud">
<div class="assumption-icon">R</div>
<div class="assumption-copy">
<strong>Idealized rigid-body assumption</strong>
<span>
Neglect beam mass, deformation, and pivot friction. The force is a
perpendicular point load, so torque is compared using τ = Fd⊥.
</span>
</div>
</section>
<p class="sr-only">
Two levers receive the same downward force of 20 newtons. The first has
a one-meter lever arm and produces 20 newton-meters of torque. The second
has a two-meter lever arm and produces 40 newton-meters of torque.
</p>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, and scene
// ------------------------------------------------------------
const mount = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Three-dimensional torque lever comparison");
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe7eb);
scene.fog = new THREE.Fog(0xdfe7eb, 18, 34);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const controls = {
target: new THREE.Vector3(0.45, 2.25, 0),
radius: 18,
theta: 0,
phi: 1.30,
zoom: 1,
dragging: false,
lastX: 0,
lastY: 0
};
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xd6e0e5,
roughness: 0.94,
metalness: 0
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe8eef1,
roughness: 1,
metalness: 0
}),
ink: new THREE.MeshStandardMaterial({
color: 0x172c43,
roughness: 0.62,
metalness: 0.08
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf2f0e9,
roughness: 0.76,
metalness: 0
}),
teal: new THREE.MeshStandardMaterial({
color: 0x27a8a0,
roughness: 0.48,
metalness: 0.04
}),
blue: new THREE.MeshStandardMaterial({
color: 0x5578d9,
roughness: 0.48,
metalness: 0.04
}),
gold: new THREE.MeshStandardMaterial({
color: 0xf5b942,
emissive: 0xf5b942,
emissiveIntensity: 0.08,
roughness: 0.38,
metalness: 0.08
}),
coral: new THREE.MeshStandardMaterial({
color: 0xf16c5d,
roughness: 0.48,
metalness: 0.04
}),
leftDisc: new THREE.MeshStandardMaterial({
color: 0xd3ebe7,
roughness: 0.9
}),
rightDisc: new THREE.MeshStandardMaterial({
color: 0xdce5fb,
roughness: 0.9
})
};
// ------------------------------------------------------------
// Geometry helpers, implemented without addons
// ------------------------------------------------------------
function roundedRectShape(width, height, radius) {
const r = Math.min(radius, width * 0.45, height * 0.45);
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function makeRoundedBox(width, height, depth, radius, material) {
const bevel = Math.min(0.055, depth * 0.2, radius * 0.32);
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
bevelEnabled: true,
bevelThickness: bevel,
bevelSize: bevel,
bevelSegments: 3,
curveSegments: 10,
steps: 1
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeTriangleSupport(material) {
const shape = new THREE.Shape();
shape.moveTo(-0.78, 0);
shape.lineTo(0.78, 0);
shape.lineTo(0, 1.72);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.55,
bevelEnabled: true,
bevelThickness: 0.055,
bevelSize: 0.055,
bevelSegments: 3,
steps: 1
});
geometry.translate(0, 0, -0.275);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addLine(points, material, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
parent.add(line);
return line;
}
// ------------------------------------------------------------
// Environment
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 22),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = 0;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(32, 14),
materials.wall
);
wall.position.set(0, 6.1, -5.6);
wall.receiveShadow = true;
scene.add(wall);
const baseboard = makeRoundedBox(32, 0.25, 0.2, 0.08, materials.ink);
baseboard.position.set(0, 0.12, -5.42);
scene.add(baseboard);
const wallLineMaterial = new THREE.LineBasicMaterial({
color: 0x9cabb5,
transparent: true,
opacity: 0.18
});
for (let x = -14; x <= 14; x += 2) {
addLine(
[
new THREE.Vector3(x, 0.3, -5.47),
new THREE.Vector3(x, 10.8, -5.47)
],
wallLineMaterial
);
}
for (let y = 0.8; y <= 10; y += 1.5) {
addLine(
[
new THREE.Vector3(-14, y, -5.47),
new THREE.Vector3(14, y, -5.47)
],
wallLineMaterial
);
}
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf7fbff, 0x81909b, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff4dc, 3.3);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcde4ff, 1.25);
fillLight.position.set(8, 6, 4);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xffd58f, 35, 16, 2);
rimLight.position.set(-6, 5, 3);
scene.add(rimLight);
// ------------------------------------------------------------
// World labels
// ------------------------------------------------------------
const labels = [];
function addWorldLabel(html, position, className, accent) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
if (accent) {
element.style.setProperty("--accent", accent);
}
labelLayer.appendChild(element);
labels.push({ element, position: position.clone() });
return element;
}
// ------------------------------------------------------------
// Torque arc and gauge builders
// ------------------------------------------------------------
const animatedTorqueMaterials = [];
function addTorqueArc({
pivot,
radius,
sweep,
color,
labelPosition
}) {
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.15,
roughness: 0.38,
metalness: 0.08
});
animatedTorqueMaterials.push(material);
// Faint full ring provides a common-radius reference.
const guide = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.014, 8, 96),
new THREE.MeshBasicMaterial({
color: 0x738594,
transparent: true,
opacity: 0.3
})
);
guide.position.set(pivot.x, pivot.y, pivot.z);
scene.add(guide);
const startAngle = 2.35;
const points = [];
for (let i = 0; i <= 90; i++) {
const t = i / 90;
const angle = startAngle - sweep * t;
points.push(
new THREE.Vector3(
pivot.x + Math.cos(angle) * radius,
pivot.y + Math.sin(angle) * radius,
pivot.z
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 110, 0.055, 12, false),
material
);
tube.castShadow = true;
scene.add(tube);
const endAngle = startAngle - sweep;
const tangent = new THREE.Vector3(
Math.sin(endAngle),
-Math.cos(endAngle),
0
).normalize();
const headHeight = 0.27;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.16, headHeight, 18),
material
);
const endPoint = points[points.length - 1];
head.position.copy(endPoint).addScaledVector(tangent, -headHeight / 2);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
head.castShadow = true;
scene.add(head);
return labelPosition;
}
function addGauge(leftX, value, maxValue, color) {
const width = 2.35;
const height = 0.29;
const fillFraction = value / maxValue;
const backing = makeRoundedBox(width, height, 0.09, 0.12, materials.ink);
backing.rotation.x = -Math.PI / 2;
backing.position.set(leftX + width / 2, 0.16, 2.05);
scene.add(backing);
const fillMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.08,
roughness: 0.45
});
const fillWidth = (width - 0.12) * fillFraction;
const fill = makeRoundedBox(
fillWidth,
height - 0.07,
0.045,
0.075,
fillMaterial
);
fill.rotation.x = -Math.PI / 2;
fill.position.set(
leftX + 0.06 + fillWidth / 2,
0.225,
2.03
);
scene.add(fill);
// A common scale tick at the 50 N·m reference.
const tick = makeRoundedBox(0.025, 0.21, 0.04, 0.01, materials.cream);
tick.rotation.x = -Math.PI / 2;
tick.position.set(leftX + width - 0.07, 0.24, 2.01);
scene.add(tick);
return new THREE.Vector3(leftX + width / 2, 0.62, 2.05);
}
// ------------------------------------------------------------
// Lever builder
// ------------------------------------------------------------
function buildLever({
pivotX,
armLength,
beamMaterial,
discMaterial,
discRadius,
torqueColor,
torqueSweep,
caseTitle,
casePosition,
torqueLabelPosition
}) {
const pivot = new THREE.Vector3(pivotX, 2.47, 0.73);
const endpointX = pivotX + armLength;
// Large solid backdrop disc.
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(discRadius, discRadius, 0.14, 72),
discMaterial
);
disc.geometry.rotateX(Math.PI / 2);
disc.position.set(pivotX + 0.5, 2.83, -1.35);
disc.receiveShadow = true;
scene.add(disc);
const discRing = new THREE.Mesh(
new THREE.TorusGeometry(discRadius, 0.025, 8, 100),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.55
})
);
discRing.position.set(pivotX + 0.5, 2.83, -1.265);
scene.add(discRing);
// Circular station base.
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.96, 1.02, 0.23, 48),
materials.ink
);
base.position.set(pivotX, 0.14, 0);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseInset = new THREE.Mesh(
new THREE.CylinderGeometry(0.80, 0.80, 0.055, 48),
beamMaterial
);
baseInset.position.set(pivotX, 0.285, 0);
baseInset.receiveShadow = true;
scene.add(baseInset);
// Triangular support.
const support = makeTriangleSupport(materials.cream);
support.position.set(pivotX, 0.36, 0);
scene.add(support);
// Fixed axis and front cap.
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.22, 1.28, 32),
materials.ink
);
axle.geometry.rotateX(Math.PI / 2);
axle.position.set(pivotX, 2.40, 0);
axle.castShadow = true;
scene.add(axle);
const axleCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.32, 0.32, 0.18, 40),
materials.coral
);
axleCap.geometry.rotateX(Math.PI / 2);
axleCap.position.set(pivotX, 2.40, 0.69);
axleCap.castShadow = true;
scene.add(axleCap);
const axleCenter = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.205, 28),
materials.ink
);
axleCenter.geometry.rotateX(Math.PI / 2);
axleCenter.position.set(pivotX, 2.40, 0.79);
scene.add(axleCenter);
// Solid lever beam.
const beam = makeRoundedBox(
armLength + 0.8,
0.28,
0.34,
0.13,
beamMaterial
);
beam.position.set(pivotX + armLength / 2, 2.48, 0);
scene.add(beam);
// Gold application point.
const applicationPoint = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.42, 28),
materials.gold
);
applicationPoint.position.set(endpointX, 2.48, 0);
applicationPoint.castShadow = true;
scene.add(applicationPoint);
// Equal downward force arrows.
const arrowZ = 0.43;
const arrowTipY = 2.70;
const headHeight = 0.38;
const shaftTopY = 4.10;
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.17, headHeight, 24),
materials.gold
);
arrowHead.rotation.z = Math.PI;
arrowHead.position.set(endpointX, arrowTipY + headHeight / 2, arrowZ);
arrowHead.castShadow = true;
scene.add(arrowHead);
const shaftHeight = shaftTopY - (arrowTipY + headHeight);
const arrowShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, shaftHeight, 18),
materials.gold
);
arrowShaft.position.set(
endpointX,
arrowTipY + headHeight + shaftHeight / 2,
arrowZ
);
arrowShaft.castShadow = true;
scene.add(arrowShaft);
// Dashed dimension line for the perpendicular lever arm.
const dimensionMaterial = new THREE.LineDashedMaterial({
color: 0x43596d,
dashSize: 0.16,
gapSize: 0.11,
transparent: true,
opacity: 0.88
});
const extensionMaterial = new THREE.LineBasicMaterial({
color: 0x647789,
transparent: true,
opacity: 0.65
});
addLine(
[
new THREE.Vector3(pivotX, 1.28, 0.84),
new THREE.Vector3(endpointX, 1.28, 0.84)
],
dimensionMaterial
);
for (const x of [pivotX, endpointX]) {
addLine(
[
new THREE.Vector3(x, 1.14, 0.84),
new THREE.Vector3(x, 1.42, 0.84)
],
extensionMaterial
);
addLine(
[
new THREE.Vector3(x, 1.45, 0.84),
new THREE.Vector3(x, 2.39, 0.84)
],
extensionMaterial
);
}
// Torque arc: the right arc is exactly twice as long.
addTorqueArc({
pivot,
radius: 0.86,
sweep: torqueSweep,
color: torqueColor,
labelPosition: torqueLabelPosition
});
// Common-scale torque gauge on the floor.
const gaugeLabelPosition = addGauge(
pivotX,
20 * (armLength / 1),
50,
torqueColor
);
// World labels.
addWorldLabel(caseTitle, casePosition, "case-label");
addWorldLabel(
`F = 20 N ↓`,
new THREE.Vector3(endpointX, 4.42, arrowZ),
"force-label"
);
addWorldLabel(
`d = ${armLength} m`,
new THREE.Vector3(
pivotX + armLength / 2,
1.06,
0.93
),
"distance-label"
);
addWorldLabel(
torqueSweep > 3
? "<strong>τ = 40 N·m</strong><span>2× torque</span>"
: "<strong>τ = 20 N·m</strong><span>1× torque</span>",
torqueLabelPosition,
"torque-label",
torqueColor
);
addWorldLabel(
torqueSweep > 3 ? "40 N·m" : "20 N·m",
gaugeLabelPosition,
"gauge-label"
);
}
// ------------------------------------------------------------
// Scene contents
// ------------------------------------------------------------
buildLever({
pivotX: -3.8,
armLength: 1,
beamMaterial: materials.teal,
discMaterial: materials.leftDisc,
discRadius: 2.22,
torqueColor: 0xf0ad3d,
torqueSweep: 2.35,
caseTitle: "A · SHORT ARM",
casePosition: new THREE.Vector3(-3.3, 5.08, -0.8),
torqueLabelPosition: new THREE.Vector3(-4.25, 3.72, 1.0)
});
buildLever({
pivotX: 1.6,
armLength: 2,
beamMaterial: materials.blue,
discMaterial: materials.rightDisc,
discRadius: 2.80,
torqueColor: 0xf16c5d,
torqueSweep: 4.70,
caseTitle: "B · LONG ARM",
casePosition: new THREE.Vector3(2.2, 5.08, -0.8),
torqueLabelPosition: new THREE.Vector3(0.55, 3.72, 1.0)
});
// ------------------------------------------------------------
// Direct camera controls — no examples/addons
// ------------------------------------------------------------
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.theta = clamp(
controls.theta - dx * 0.005,
-0.68,
0.68
);
controls.phi = clamp(
controls.phi + dy * 0.004,
0.92,
1.48
);
updateCamera();
});
function endPointer(event) {
controls.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.55
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Resize and label projection
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
const worldWidth = 12.8;
const worldHeight = Math.max(8.0, worldWidth / aspect);
camera.left = -worldWidth / 2;
camera.right = worldWidth / 2;
camera.top = worldHeight / 2;
camera.bottom = -worldHeight / 2;
camera.updateProjectionMatrix();
updateCamera();
updateLabels();
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
materials.gold.emissiveIntensity =
0.07 + Math.sin(elapsed * 2.1) * 0.035;
animatedTorqueMaterials.forEach((material, index) => {
material.emissiveIntensity =
0.12 +
Math.sin(elapsed * 1.9 + index * 1.4) * 0.055;
});
updateLabels();
renderer.render(scene, camera);
}
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```