Prompt specification
Build or customize the Three.js 3D scene "Crane load force-diagram exhibit" 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: Crane load force-diagram exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/crane-load-force-diagram-exhibit-x1439
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring force vectors and their resultant. Compose a suspended model load with two angled supports and a nearby vector diagram; show equilibrium under stated idealized tension assumptions and keep force directions aligned. Voxel style.
Working Three.js Starter (crane-load-force-diagram-exhibit-x1439):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Force Equilibrium</title>
<style>
:root {
--ink: #15262d;
--muted: #63747a;
--paper: #f3f0e7;
--panel: #fbfaf5;
--line: #cfd5d1;
--tension: #f3ad35;
--resultant: #18a999;
--weight: #eb6659;
--dark: #0e1b21;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: var(--dark);
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
button {
font: inherit;
}
#app {
width: 100%;
height: 100dvh;
display: flex;
flex-direction: column;
}
.topbar {
height: 64px;
flex: 0 0 64px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
background: #101d23;
color: #edf2ef;
border-bottom: 1px solid #2a3b42;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.voxel-mark {
position: relative;
width: 30px;
height: 30px;
flex: 0 0 30px;
}
.voxel-mark i {
position: absolute;
display: block;
width: 14px;
height: 14px;
background: var(--tension);
box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.18);
}
.voxel-mark i:nth-child(1) {
left: 0;
top: 8px;
}
.voxel-mark i:nth-child(2) {
left: 16px;
top: 0;
background: var(--resultant);
}
.voxel-mark i:nth-child(3) {
left: 16px;
top: 16px;
background: #7f949c;
}
.brand-title {
font-size: 13px;
letter-spacing: 0.12em;
white-space: nowrap;
}
.brand-title span {
color: #8fa2aa;
margin-left: 10px;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
height: 32px;
padding: 0 11px;
border: 1px solid #365057;
color: #b9c8cc;
font-size: 10px;
letter-spacing: 0.08em;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
background: var(--resultant);
box-shadow: 0 0 10px rgba(24, 169, 153, 0.8);
}
.icon-button {
height: 32px;
padding: 0 12px;
border: 1px solid #3a4c53;
background: #18282f;
color: #dfe7e4;
cursor: pointer;
font-size: 10px;
letter-spacing: 0.06em;
}
.icon-button:hover {
border-color: #789097;
background: #20343c;
}
.icon-button[aria-pressed="false"] {
color: #73858b;
}
main {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dce3df;
}
#scene {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.scene-readout {
position: absolute;
top: 22px;
left: 24px;
z-index: 3;
pointer-events: none;
}
.scene-readout small {
display: block;
margin-bottom: 6px;
color: #65767a;
font-size: 9px;
letter-spacing: 0.18em;
}
.scene-readout strong {
display: block;
font-size: 15px;
letter-spacing: 0.07em;
color: #20353c;
}
.live-pill {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 8px;
background: rgba(247, 249, 245, 0.76);
border: 1px solid rgba(67, 91, 97, 0.25);
color: #52676d;
font-size: 8px;
letter-spacing: 0.14em;
}
.live-pill::before {
content: "";
width: 5px;
height: 5px;
background: var(--resultant);
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
pointer-events: none;
transition: opacity 150ms ease;
}
#labels.hidden {
opacity: 0;
}
.world-label {
position: absolute;
padding: 6px 8px;
transform: translate(-50%, -50%);
border: 1px solid rgba(207, 219, 215, 0.25);
border-left: 3px solid #82969d;
background: rgba(15, 29, 35, 0.88);
color: white;
font-size: 9px;
line-height: 1;
letter-spacing: 0.045em;
white-space: nowrap;
box-shadow: 0 4px 12px rgba(15, 28, 33, 0.15);
}
.world-label.tension {
border-left-color: var(--tension);
}
.world-label.resultant {
border-left-color: var(--resultant);
}
.world-label.weight {
border-left-color: var(--weight);
}
.world-label.anchor {
padding: 4px 7px;
background: rgba(25, 43, 50, 0.76);
color: #d7e0de;
}
.legend {
position: absolute;
left: 22px;
bottom: 22px;
z-index: 3;
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
max-width: calc(100% - 44px);
padding: 10px 12px;
background: rgba(244, 247, 242, 0.86);
border: 1px solid rgba(73, 94, 99, 0.24);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #42575e;
font-size: 9px;
letter-spacing: 0.03em;
}
.legend-swatch {
width: 10px;
height: 10px;
}
.legend-swatch.tension {
background: var(--tension);
}
.legend-swatch.resultant {
background: var(--resultant);
}
.legend-swatch.weight {
background: var(--weight);
}
.controls-hint {
position: absolute;
right: 22px;
bottom: 24px;
z-index: 3;
color: rgba(40, 61, 68, 0.72);
font-size: 8px;
letter-spacing: 0.08em;
pointer-events: none;
}
aside {
min-height: 0;
overflow-y: auto;
padding: 22px;
background:
linear-gradient(rgba(83, 102, 108, 0.045) 1px, transparent 1px),
linear-gradient(90deg, rgba(83, 102, 108, 0.045) 1px, transparent 1px),
var(--paper);
background-size: 22px 22px;
border-left: 1px solid #bdc6c2;
}
.panel-kicker {
margin-bottom: 7px;
color: #738287;
font-size: 8px;
letter-spacing: 0.18em;
}
h1 {
margin: 0 0 18px;
font-size: 22px;
line-height: 1.15;
letter-spacing: -0.04em;
}
.card {
background: var(--panel);
border: 1px solid #cdd3ce;
box-shadow: 4px 4px 0 rgba(50, 73, 80, 0.07);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 13px 14px;
border-bottom: 1px solid #d8ddd8;
}
.card-header h2 {
margin: 0;
font-size: 10px;
letter-spacing: 0.12em;
}
.card-index {
padding: 4px 6px;
background: #e9ece7;
color: #6b7b80;
font-size: 8px;
}
.diagram-wrap {
padding: 5px 10px 0;
}
#vector-diagram {
width: 100%;
height: auto;
display: block;
}
.vector-equation {
padding: 13px 14px 15px;
border-top: 1px solid #d8ddd8;
text-align: center;
font-size: 12px;
letter-spacing: 0.02em;
}
.vector-equation strong {
color: #0d8f83;
}
.vector-equation small {
display: block;
margin-top: 7px;
color: #758388;
font-size: 8px;
letter-spacing: 0.08em;
}
.assumptions {
margin-top: 20px;
padding: 17px;
}
.assumptions h2 {
margin: 0 0 15px;
font-size: 11px;
letter-spacing: 0.12em;
}
.assumption-list {
margin: 0;
}
.assumption-list div {
display: flex;
justify-content: space-between;
gap: 15px;
padding: 9px 0;
border-bottom: 1px dashed #d5dad5;
font-size: 9px;
}
.assumption-list dt {
color: #718085;
}
.assumption-list dd {
margin: 0;
text-align: right;
font-weight: 700;
}
.equation-box {
margin-top: 15px;
padding: 13px;
background: #182a31;
color: #eef3f0;
font-size: 11px;
line-height: 1.7;
}
.equation-box span {
color: #8fa4aa;
}
.balance-check {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.balance-check div {
padding: 10px;
border: 1px solid #d3dad5;
background: #f4f5f0;
font-size: 8px;
line-height: 1.6;
}
.balance-check b {
display: block;
margin-bottom: 3px;
color: #0a9184;
font-size: 10px;
}
.assumption-note {
margin: 14px 0 0;
color: #6b7c81;
font-size: 8px;
line-height: 1.65;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100dvh;
}
main {
display: block;
}
#stage {
height: 62dvh;
min-height: 480px;
}
aside {
overflow: visible;
border-top: 1px solid #bdc6c2;
border-left: 0;
}
.diagram-card,
.assumptions {
max-width: 580px;
margin-left: auto;
margin-right: auto;
}
.assumptions {
margin-top: 18px;
}
}
@media (max-width: 560px) {
.topbar {
height: auto;
min-height: 64px;
padding: 12px 14px;
}
.brand-title span,
.status {
display: none;
}
.top-actions {
gap: 5px;
}
.icon-button {
padding: 0 8px;
}
#stage {
height: 66dvh;
min-height: 500px;
}
.scene-readout {
top: 16px;
left: 16px;
}
.scene-readout strong {
font-size: 12px;
}
.legend {
left: 12px;
bottom: 12px;
gap: 7px 10px;
}
.controls-hint {
display: none;
}
aside {
padding: 16px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="voxel-mark" aria-hidden="true">
<i></i><i></i><i></i>
</div>
<div class="brand-title">
STATIC LOAD LAB
<span>/ MODEL 04</span>
</div>
</div>
<div class="top-actions">
<div class="status">
<span class="status-dot"></span>
EQUILIBRIUM · NET FORCE 0 N
</div>
<button id="labels-button" class="icon-button" aria-pressed="true">
LABELS ON
</button>
<button id="reset-button" class="icon-button">
RESET VIEW
</button>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive Three.js force equilibrium scene">
<canvas id="scene" tabindex="0"></canvas>
<div class="scene-readout">
<small>STRUCTURAL STUDY / 04</small>
<strong>SYMMETRIC SUSPENSION</strong>
<span class="live-pill">FORCE VECTORS LIVE</span>
</div>
<div id="labels"></div>
<div class="legend">
<div class="legend-item">
<span class="legend-swatch tension"></span>
T₁, T₂ = 70.71 N
</div>
<div class="legend-item">
<span class="legend-swatch resultant"></span>
R = 100 N
</div>
<div class="legend-item">
<span class="legend-swatch weight"></span>
W = 100 N
</div>
</div>
<div class="controls-hint">DRAG TO ORBIT · WHEEL TO ZOOM</div>
</section>
<aside>
<div class="panel-kicker">FREE-BODY ANALYSIS</div>
<h1>Balanced Under<br>Symmetric Tension</h1>
<section class="card diagram-card">
<div class="card-header">
<h2>VECTOR DIAGRAM</h2>
<span class="card-index">01 / 02</span>
</div>
<div class="diagram-wrap">
<svg
id="vector-diagram"
viewBox="0 0 360 310"
role="img"
aria-label="Two equal tension vectors combine into an upward resultant that balances the downward weight"
>
<defs>
<marker
id="arrow-tension"
viewBox="0 0 10 10"
refX="8.5"
refY="5"
markerWidth="10"
markerHeight="10"
markerUnits="userSpaceOnUse"
orient="auto"
>
<path d="M0 0 L10 5 L0 10 Z" fill="#d89119"/>
</marker>
<marker
id="arrow-result"
viewBox="0 0 10 10"
refX="8.5"
refY="5"
markerWidth="11"
markerHeight="11"
markerUnits="userSpaceOnUse"
orient="auto"
>
<path d="M0 0 L10 5 L0 10 Z" fill="#0d9e90"/>
</marker>
<marker
id="arrow-weight"
viewBox="0 0 10 10"
refX="8.5"
refY="5"
markerWidth="10"
markerHeight="10"
markerUnits="userSpaceOnUse"
orient="auto"
>
<path d="M0 0 L10 5 L0 10 Z" fill="#df554b"/>
</marker>
</defs>
<!-- Construction axes -->
<line
x1="30" y1="165" x2="330" y2="165"
stroke="#d5ddd8" stroke-width="1" stroke-dasharray="4 5"
/>
<line
x1="180" y1="18" x2="180" y2="296"
stroke="#d5ddd8" stroke-width="1" stroke-dasharray="4 5"
/>
<!-- Component projections -->
<path
d="M115 100 L180 100 M180 100 L245 100"
fill="none" stroke="#d6ddd9" stroke-width="1"
stroke-dasharray="3 4"
/>
<path
d="M115 100 L115 165 M245 100 L245 165"
fill="none" stroke="#d6ddd9" stroke-width="1"
stroke-dasharray="3 4"
/>
<!-- Tension vectors -->
<line
x1="180" y1="165" x2="115" y2="100"
stroke="#d89119" stroke-width="3.5"
marker-end="url(#arrow-tension)"
/>
<line
x1="180" y1="165" x2="245" y2="100"
stroke="#d89119" stroke-width="3.5"
marker-end="url(#arrow-tension)"
/>
<!-- Resultant and weight -->
<line
x1="180" y1="165" x2="180" y2="35"
stroke="#0d9e90" stroke-width="4"
marker-end="url(#arrow-result)"
/>
<line
x1="180" y1="165" x2="180" y2="295"
stroke="#df554b" stroke-width="3.5"
marker-end="url(#arrow-weight)"
/>
<!-- Origin -->
<rect x="175.5" y="160.5" width="9" height="9" fill="#21363d"/>
<!-- Vector labels -->
<g
fill="#24383f"
font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"
font-size="10"
font-weight="700"
>
<text x="78" y="91">T₁</text>
<text x="78" y="103" font-size="8" fill="#7a898d">70.71 N</text>
<text x="266" y="91">T₂</text>
<text x="266" y="103" font-size="8" fill="#7a898d">70.71 N</text>
<text x="193" y="29" fill="#0b8d81">R = 100 N</text>
<text x="193" y="277" fill="#d24d45">W = 100 N</text>
</g>
<g
fill="#8b989b"
font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"
font-size="8"
>
<text x="48" y="157">0</text>
<text x="48" y="91">45°</text>
<text x="289" y="91">45°</text>
<text x="108" y="94">−50 N</text>
<text x="238" y="94">+50 N</text>
<text x="185" y="115">+50 N</text>
</g>
</svg>
</div>
<div class="vector-equation">
<strong>T₁ + T₂ = R = 100 N ↑</strong>
<small>R + W = 0 · EQUILIBRIUM</small>
</div>
</section>
<section class="assumptions card">
<div class="card-header">
<h2>STATED ASSUMPTIONS</h2>
<span class="card-index">02 / 02</span>
</div>
<dl class="assumption-list">
<div>
<dt>Specified load weight</dt>
<dd>W = 100 N</dd>
</div>
<div>
<dt>Cable angle from vertical</dt>
<dd>θ₁ = θ₂ = 45°</dd>
</div>
<div>
<dt>Cable model</dt>
<dd>Massless / inextensible</dd>
</div>
<div>
<dt>Geometry</dt>
<dd>Symmetric</dd>
</div>
<div>
<dt>Load model</dt>
<dd>Rigid / centered mass</dd>
</div>
</dl>
<div class="equation-box">
<span>Tension from vertical balance</span><br>
2T cos(45°) = 100 N<br>
<strong>T = 70.71 N</strong><br><br>
<span>Force on load</span><br>
T₁ = (−50, +50, 0) N<br>
T₂ = (+50, +50, 0) N<br>
R = (0, +100, 0) N
</div>
<div class="balance-check">
<div>
<b>ΣFx = 0 N</b>
−50 + 50 = 0
</div>
<div>
<b>ΣFy = 0 N</b>
50 + 50 − 100 = 0
</div>
</div>
<p class="assumption-note">
Each tension arrow acts on the load and points from its attachment
toward the corresponding support. The cable geometry and vector
diagram use the same 45° angle. The resultant of the two tensions
is upward and exactly opposes the 100 N weight.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const stage = document.querySelector("#stage");
const labelLayer = document.querySelector("#labels");
const COLORS = {
tension: 0xf3ad35,
tensionDark: 0xd8901d,
resultant: 0x18a999,
weight: 0xeb6659,
load: 0x536d78,
loadLight: 0x6d8791,
steel: 0x263d46,
steelLight: 0x45606a,
background: 0xdce3df,
floor: 0xd2dad5
};
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
scene.fog = new THREE.Fog(COLORS.background, 22, 43);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const target = new THREE.Vector3(0, 2.4, 0);
const orbit = {
theta: 0.66,
phi: 1.15,
radius: 16.5,
desiredTheta: 0.66,
desiredPhi: 1.15,
desiredRadius: 16.5
};
const hemi = new THREE.HemisphereLight(0xf7fbf6, 0x52646a, 2.1);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff8e8, 3.1);
keyLight.position.set(8, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9e4e6, 1.25);
rimLight.position.set(-10, 8, -8);
scene.add(rimLight);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
flatShading: true,
...options
})
);
}
return materialCache.get(key);
}
function voxelBox(
width,
height,
depth,
color,
position,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, options.material || {})
);
mesh.position.copy(position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.outline !== false) {
const edges = new THREE.EdgesGeometry(mesh.geometry);
const outline = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({
color: options.outlineColor || 0x263a40,
transparent: true,
opacity: options.outlineOpacity ?? 0.36
})
);
mesh.add(outline);
}
scene.add(mesh);
return mesh;
}
function beamBetween(start, end, width, color, options = {}) {
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, width),
material(color, options.material || {})
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (options.outline !== false) {
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x172b32,
transparent: true,
opacity: 0.55
})
);
mesh.add(outline);
}
scene.add(mesh);
return mesh;
}
function voxelArrow(start, direction, length, color, width = 0.14) {
const dir = direction.clone().normalize();
const headSize = width * 2.8;
const shaftLength = Math.max(0.1, length - headSize * 1.15);
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(width, shaftLength, width),
material(color, {
roughness: 0.55,
metalness: 0.12,
emissive: color,
emissiveIntensity: 0.06
})
);
shaft.position.copy(start).addScaledVector(dir, shaftLength * 0.5);
shaft.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
dir
);
shaft.castShadow = true;
scene.add(shaft);
const headSpecs = [
{ size: headSize, distance: headSize * 0.62 },
{ size: headSize * 0.68, distance: headSize * 0.27 },
{ size: headSize * 0.34, distance: headSize * 0.03 }
];
for (const spec of headSpecs) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(spec.size, spec.size, spec.size),
material(color, {
roughness: 0.5,
metalness: 0.12,
emissive: color,
emissiveIntensity: 0.06
})
);
block.position.copy(start).addScaledVector(dir, length - spec.distance);
block.quaternion.copy(shaft.quaternion);
block.castShadow = true;
scene.add(block);
}
}
// Floor and reference grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
material(COLORS.floor, { roughness: 1, metalness: 0 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.52;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x879b9d, 0xaebbb7);
grid.position.y = -1.505;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// Model constants. The exact attachment and anchor coordinates produce
// a 45-degree cable angle: horizontal delta = 4 m, vertical delta = 4 m.
const FLOOR_Y = -1.5;
const ATTACH_Y = 2.7;
const ANCHOR_Y = 6.7;
const LOAD_X = 1.7;
const ANCHOR_X = 5.7;
const FORCE_SCALE = 0.032;
// Two segmented voxel towers.
for (const side of [-1, 1]) {
const x = side * ANCHOR_X;
const segmentCount = 11;
const segmentHeight = (ANCHOR_Y - FLOOR_Y) / segmentCount;
voxelBox(
2.05,
0.28,
2.05,
0x344b53,
new THREE.Vector3(x, FLOOR_Y + 0.14, 0),
{ outlineOpacity: 0.45 }
);
for (let i = 0; i < segmentCount; i++) {
const y = FLOOR_Y + segmentHeight * (i + 0.5);
const towerColor = i % 2 === 0
? COLORS.steelLight
: COLORS.steel;
voxelBox(
1.05,
segmentHeight - 0.035,
1.05,
towerColor,
new THREE.Vector3(x, y, 0),
{ outlineOpacity: 0.3 }
);
}
voxelBox(
1.4,
0.18,
1.4,
0x5d737b,
new THREE.Vector3(x, ANCHOR_Y - 0.07, 0)
);
voxelBox(
0.34,
0.34,
0.34,
COLORS.tension,
new THREE.Vector3(x, ANCHOR_Y + 0.08, 0.1)
);
}
// Suspended voxel load: 4 × 2 × 2 blocks.
const cell = 0.8;
for (let ix = 0; ix < 4; ix++) {
for (let iy = 0; iy < 2; iy++) {
for (let iz = 0; iz < 2; iz++) {
const x = (ix - 1.5) * cell;
const y = 1.2 + iy * cell;
const z = (iz - 0.5) * cell;
let color = COLORS.load;
if (iy === 1) color = COLORS.loadLight;
if (ix === 0 || ix === 3) color = 0x3e5660;
voxelBox(
cell - 0.035,
cell - 0.035,
cell - 0.035,
color,
new THREE.Vector3(x, y, z),
{ outlineOpacity: 0.42 }
);
}
}
}
// Front-face load plate.
const plateCanvas = document.createElement("canvas");
plateCanvas.width = 512;
plateCanvas.height = 128;
const plateContext = plateCanvas.getContext("2d");
plateContext.clearRect(0, 0, 512, 128);
plateContext.fillStyle = "rgba(20, 38, 45, 0.93)";
plateContext.fillRect(4, 5, 504, 118);
plateContext.fillStyle = "#f3ad35";
plateContext.fillRect(25, 28, 14, 72);
plateContext.fillRect(47, 28, 14, 72);
plateContext.fillStyle = "#eef3ef";
plateContext.font = "bold 40px monospace";
plateContext.textAlign = "left";
plateContext.fillText("100 N / LOAD", 90, 65);
plateContext.fillStyle = "#93a6ab";
plateContext.font = "19px monospace";
plateContext.fillText("RIGID CENTERED MASS", 92, 95);
const plateTexture = new THREE.CanvasTexture(plateCanvas);
plateTexture.colorSpace = THREE.SRGBColorSpace;
const plate = new THREE.Mesh(
new THREE.PlaneGeometry(2.85, 0.7),
new THREE.MeshBasicMaterial({
map: plateTexture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
plate.position.set(0, 1.56, 0.795);
scene.add(plate);
// Lifting brackets.
for (const side of [-1, 1]) {
const x = side * LOAD_X;
voxelBox(
0.28,
0.42,
0.5,
COLORS.tensionDark,
new THREE.Vector3(x, 2.52, 0)
);
voxelBox(
0.48,
0.18,
0.56,
COLORS.tension,
new THREE.Vector3(x, 2.66, 0)
);
}
// Exact cable geometry and force-vector geometry.
const attachmentLeft = new THREE.Vector3(-LOAD_X, ATTACH_Y, 0);
const attachmentRight = new THREE.Vector3(LOAD_X, ATTACH_Y, 0);
const anchorLeft = new THREE.Vector3(-ANCHOR_X, ANCHOR_Y, 0);
const anchorRight = new THREE.Vector3(ANCHOR_X, ANCHOR_Y, 0);
beamBetween(attachmentLeft, anchorLeft, 0.11, COLORS.steel);
beamBetween(attachmentRight, anchorRight, 0.11, COLORS.steel);
const tensionLength = 70.710678 * FORCE_SCALE;
const directionLeft = anchorLeft.clone().sub(attachmentLeft).normalize();
const directionRight = anchorRight.clone().sub(attachmentRight).normalize();
// Small forward offsets keep the arrows readable while preserving their
// exact in-plane directions.
const tensionStartLeft = attachmentLeft.clone();
const tensionStartRight = attachmentRight.clone();
tensionStartLeft.z = 0.61;
tensionStartRight.z = 0.46;
voxelArrow(
tensionStartLeft,
directionLeft,
tensionLength,
COLORS.tension,
0.14
);
voxelArrow(
tensionStartRight,
directionRight,
tensionLength,
COLORS.tension,
0.14
);
// Resultant of the two tensions and the opposing weight.
const centerOfMass = new THREE.Vector3(0, 1.6, 0);
const resultantStart = centerOfMass.clone();
resultantStart.z = 0.79;
const weightStart = centerOfMass.clone();
weightStart.z = 0.95;
voxelArrow(
resultantStart,
new THREE.Vector3(0, 1, 0),
100 * FORCE_SCALE,
COLORS.resultant,
0.17
);
voxelArrow(
weightStart,
new THREE.Vector3(0, -1, 0),
100 * FORCE_SCALE,
COLORS.weight,
0.16
);
// HTML labels projected from world positions.
const labelDefinitions = [
{
text: "T₁ 70.71 N",
className: "tension",
position: attachmentLeft.clone().addScaledVector(directionLeft, 1.05),
offset: [-58, -13]
},
{
text: "T₂ 70.71 N",
className: "tension",
position: attachmentRight.clone().addScaledVector(directionRight, 1.05),
offset: [58, -13]
},
{
text: "R = 100 N",
className: "resultant",
position: new THREE.Vector3(0, 4.82, 0.8),
offset: [57, -8]
},
{
text: "W = 100 N",
className: "weight",
position: new THREE.Vector3(0, -1.58, 0.95),
offset: [-58, 5]
},
{
text: "A",
className: "anchor",
position: anchorLeft.clone().add(new THREE.Vector3(0, 0.18, 0)),
offset: [-11, -10]
},
{
text: "B",
className: "anchor",
position: anchorRight.clone().add(new THREE.Vector3(0, 0.18, 0)),
offset: [11, -10]
}
];
const projectedLabels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = `world-label ${definition.className}`;
element.textContent = definition.text;
labelLayer.appendChild(element);
return {
element,
position: definition.position,
offset: definition.offset
};
});
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const item of projectedLabels) {
const projected = item.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width + item.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + item.offset[1];
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
// Direct orbit camera controls: no external controls/addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function resetView() {
orbit.desiredTheta = 0.66;
orbit.desiredPhi = 1.15;
orbit.desiredRadius = 16.5;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.desiredTheta -= dx * 0.006;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.005,
0.56,
1.46
);
});
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();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius + event.deltaY * 0.012,
10.5,
26
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.querySelector("#reset-button").addEventListener("click", resetView);
const labelsButton = document.querySelector("#labels-button");
labelsButton.addEventListener("click", () => {
const enabled = labelsButton.getAttribute("aria-pressed") !== "true";
labelsButton.setAttribute("aria-pressed", String(enabled));
labelsButton.textContent = enabled ? "LABELS ON" : "LABELS OFF";
labelLayer.classList.toggle("hidden", !enabled);
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = camera.aspect < 1 ? 54 : 42;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
function updateCamera() {
orbit.theta += (orbit.desiredTheta - orbit.theta) * 0.12;
orbit.phi += (orbit.desiredPhi - orbit.phi) * 0.12;
orbit.radius += (orbit.desiredRadius - orbit.radius) * 0.12;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```