Prompt specification
Build or customize the Three.js 3D scene "Lift Cargo Within a Pull Limit" 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: Lift Cargo Within a Pull Limit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/lift-cargo-within-a-pull-limit-x3496
Scene Description Prompt:
Lift voxel cargo using pulleys under force and rope-travel limits; assume no friction and check displacement ratios. Three.js from cdnjs, one HTML file.
Working Three.js Starter (lift-cargo-within-a-pull-limit-x3496):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Pulley Hoist</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(12, 24, 41, 0.91);
--panel-border: rgba(148, 178, 211, 0.18);
--text: #edf6ff;
--muted: #91a7bd;
--cyan: #55d8ff;
--amber: #ffc857;
--green: #67e8a7;
--red: #ff7185;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.brand {
position: fixed;
top: 20px;
left: 22px;
z-index: 3;
pointer-events: none;
text-shadow: 0 2px 18px #000;
}
.brand h1 {
margin: 0;
font-size: clamp(22px, 3vw, 38px);
letter-spacing: -0.04em;
}
.brand p {
margin: 5px 0 0;
color: #a9c1d6;
font-size: 13px;
}
.badges {
display: flex;
gap: 7px;
margin-top: 12px;
flex-wrap: wrap;
}
.badge {
padding: 5px 9px;
border: 1px solid rgba(85, 216, 255, 0.24);
border-radius: 999px;
background: rgba(9, 25, 43, 0.74);
color: #bfefff;
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 5;
top: 18px;
right: 18px;
bottom: 18px;
width: 372px;
padding: 20px;
overflow-y: auto;
border: 1px solid var(--panel-border);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.42),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px);
}
.panel::-webkit-scrollbar {
width: 8px;
}
.panel::-webkit-scrollbar-thumb {
border-radius: 99px;
background: rgba(142, 174, 204, 0.25);
}
.section-title {
margin: 0 0 13px;
color: #dcecf8;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control {
margin-bottom: 17px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
margin-bottom: 8px;
}
.control-row label {
color: #c7d8e7;
font-size: 13px;
}
output {
color: var(--amber);
font-size: 13px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 99px;
appearance: none;
background:
linear-gradient(
90deg,
var(--cyan) 0 var(--fill, 50%),
rgba(130, 159, 187, 0.2) var(--fill, 50%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #dff7ff;
border-radius: 50%;
appearance: none;
background: #26bce9;
box-shadow: 0 0 0 5px rgba(38, 188, 233, 0.13);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #dff7ff;
border-radius: 50%;
background: #26bce9;
box-shadow: 0 0 0 5px rgba(38, 188, 233, 0.13);
}
.segments {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 7px 0 18px;
}
.segments button {
min-height: 42px;
border: 1px solid rgba(139, 171, 202, 0.22);
border-radius: 10px;
background: rgba(113, 145, 177, 0.08);
color: #aebfd0;
cursor: pointer;
font: inherit;
font-size: 12px;
transition: 150ms ease;
}
.segments button:hover {
border-color: rgba(85, 216, 255, 0.5);
color: white;
}
.segments button.active {
border-color: rgba(85, 216, 255, 0.75);
background: rgba(38, 188, 233, 0.15);
color: #e8faff;
box-shadow: inset 0 0 18px rgba(38, 188, 233, 0.08);
}
.segments strong {
display: block;
color: white;
font-size: 15px;
}
.status {
margin: 4px 0 17px;
padding: 13px 14px;
border: 1px solid rgba(111, 143, 172, 0.2);
border-radius: 12px;
background: rgba(91, 123, 153, 0.08);
}
.status[data-kind="ready"] {
border-color: rgba(85, 216, 255, 0.3);
}
.status[data-kind="running"] {
border-color: rgba(255, 200, 87, 0.42);
background: rgba(255, 200, 87, 0.07);
}
.status[data-kind="success"] {
border-color: rgba(103, 232, 167, 0.45);
background: rgba(103, 232, 167, 0.07);
}
.status[data-kind="warn"] {
border-color: rgba(255, 200, 87, 0.38);
background: rgba(255, 200, 87, 0.07);
}
.status[data-kind="danger"] {
border-color: rgba(255, 113, 133, 0.45);
background: rgba(255, 113, 133, 0.07);
}
.status-title {
margin-bottom: 4px;
font-size: 14px;
font-weight: 760;
}
.status-detail {
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
margin-bottom: 19px;
}
button.primary,
button.secondary {
min-height: 44px;
border-radius: 11px;
cursor: pointer;
font: inherit;
font-size: 13px;
font-weight: 750;
}
button.primary {
border: 0;
color: #042031;
background: linear-gradient(135deg, #73e5ff, #42bde9);
box-shadow: 0 8px 24px rgba(42, 175, 221, 0.2);
}
button.primary:hover {
filter: brightness(1.08);
}
button.secondary {
padding: 0 15px;
border: 1px solid rgba(145, 176, 207, 0.25);
background: rgba(126, 159, 190, 0.08);
color: #c7d8e7;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 18px;
}
.metric {
min-height: 67px;
padding: 11px;
border: 1px solid rgba(140, 169, 197, 0.12);
border-radius: 11px;
background: rgba(104, 138, 170, 0.055);
}
.metric-label {
margin-bottom: 5px;
color: #849db5;
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metric-value {
color: #edf8ff;
font-size: 16px;
font-weight: 740;
font-variant-numeric: tabular-nums;
}
.formula {
margin-bottom: 18px;
padding: 12px;
border-left: 3px solid var(--cyan);
border-radius: 0 9px 9px 0;
background: rgba(85, 216, 255, 0.065);
color: #cce8f5;
font-size: 12px;
line-height: 1.65;
}
code {
color: #ffe2a0;
font-family: "SFMono-Regular", Consolas, monospace;
}
.checks {
display: grid;
gap: 8px;
margin-bottom: 20px;
}
.check {
display: flex;
align-items: flex-start;
gap: 9px;
color: #aebfd0;
font-size: 12px;
line-height: 1.45;
}
.check .dot {
flex: 0 0 auto;
width: 8px;
height: 8px;
margin-top: 4px;
border-radius: 50%;
background: #6b7f91;
box-shadow: 0 0 0 3px rgba(107, 127, 145, 0.09);
}
.check.pass .dot {
background: var(--green);
box-shadow: 0 0 0 3px rgba(103, 232, 167, 0.1);
}
.check.warn .dot {
background: var(--amber);
box-shadow: 0 0 0 3px rgba(255, 200, 87, 0.1);
}
.check.fail .dot {
background: var(--red);
box-shadow: 0 0 0 3px rgba(255, 113, 133, 0.1);
}
.energy {
padding-top: 14px;
border-top: 1px solid rgba(139, 171, 202, 0.13);
}
.energy-row {
display: flex;
justify-content: space-between;
gap: 15px;
margin-top: 7px;
color: #8fa6bb;
font-size: 11px;
}
.energy-row strong {
color: #dbeaf5;
font-variant-numeric: tabular-nums;
}
.camera-hint {
position: fixed;
z-index: 3;
bottom: 20px;
left: 22px;
padding: 8px 11px;
border: 1px solid rgba(130, 161, 190, 0.15);
border-radius: 9px;
background: rgba(8, 20, 35, 0.7);
color: #91a8bd;
font-size: 11px;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(156, 187, 216, 0.22);
border-radius: 8px;
background: rgba(7, 17, 31, 0.82);
color: #dceeff;
font-size: 11px;
font-weight: 700;
white-space: nowrap;
transform: translate(-50%, -50%);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
}
@media (max-width: 720px) {
.brand {
top: 12px;
left: 14px;
}
.brand p,
.badges {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 55vh;
border-radius: 16px;
padding: 16px;
}
.camera-hint {
display: none;
}
.metrics {
grid-template-columns: repeat(3, 1fr);
}
.metric {
min-height: 62px;
padding: 9px;
}
.metric-value {
font-size: 14px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel cargo pulley simulation"></canvas>
<div class="brand">
<h1>Voxel Pulley Hoist</h1>
<p>Ideal force multiplication and rope-travel verification</p>
<div class="badges">
<span class="badge">No friction</span>
<span class="badge">Massless rope</span>
<span class="badge">SI units</span>
</div>
</div>
<aside class="panel">
<h2 class="section-title">Rig configuration</h2>
<div class="control">
<div class="control-row">
<label for="massRange">Cargo mass</label>
<output id="massValue">240 kg</output>
</div>
<input id="massRange" type="range" min="50" max="500" step="10" value="240">
</div>
<div class="control">
<div class="control-row">
<label for="forceRange">Applied effort force</label>
<output id="forceValue">1.50 kN</output>
</div>
<input id="forceRange" type="range" min="0" max="6000" step="10" value="1500">
</div>
<div class="control">
<div class="control-row">
<label for="travelRange">Available rope travel</label>
<output id="travelValue">4.00 m</output>
</div>
<input id="travelRange" type="range" min="0.5" max="5" step="0.1" value="4">
</div>
<div class="control">
<div class="control-row">
<label for="targetRange">Desired cargo rise</label>
<output id="targetValue">1.50 m</output>
</div>
<input id="targetRange" type="range" min="0.25" max="4" step="0.05" value="1.5">
</div>
<h2 class="section-title">Mechanical advantage</h2>
<div class="segments" role="group" aria-label="Mechanical advantage">
<button type="button" data-ma="1">
<strong>1×</strong>
1:1
</button>
<button type="button" data-ma="2" class="active">
<strong>2×</strong>
2:1
</button>
<button type="button" data-ma="4">
<strong>4×</strong>
4:1
</button>
</div>
<div id="status" class="status" data-kind="ready" aria-live="polite">
<div id="statusTitle" class="status-title">Ready to lift</div>
<div id="statusDetail" class="status-detail">
Choose a force above the minimum required effort.
</div>
</div>
<div class="actions">
<button id="toggleLift" class="primary" type="button">Start lift</button>
<button id="resetLift" class="secondary" type="button">Reset</button>
</div>
<h2 class="section-title">Live measurements</h2>
<div class="metrics">
<div class="metric">
<div class="metric-label">Required effort</div>
<div id="requiredForce" class="metric-value">1.18 kN</div>
</div>
<div class="metric">
<div class="metric-label">Maximum rise</div>
<div id="maximumRise" class="metric-value">2.00 m</div>
</div>
<div class="metric">
<div class="metric-label">Rope needed</div>
<div id="ropeNeeded" class="metric-value">3.00 m</div>
</div>
<div class="metric">
<div class="metric-label">Rope used</div>
<div id="ropeUsed" class="metric-value">0.00 m</div>
</div>
<div class="metric">
<div class="metric-label">Cargo rise</div>
<div id="cargoRise" class="metric-value">0.00 m</div>
</div>
<div class="metric">
<div class="metric-label">Observed ratio</div>
<div id="observedRatio" class="metric-value">—</div>
</div>
</div>
<div class="formula">
For an ideal <code>n</code>-part tackle:<br>
<code>Frequired = mg / n</code><br>
<code>Δcargo = Δrope / n</code><br>
Rope-to-cargo displacement ratio = <code>n:1</code>
</div>
<h2 class="section-title">Constraint checks</h2>
<div class="checks">
<div id="forceCheck" class="check">
<span class="dot"></span>
<span>Force check</span>
</div>
<div id="travelCheck" class="check">
<span class="dot"></span>
<span>Travel check</span>
</div>
<div id="ratioCheck" class="check">
<span class="dot"></span>
<span>Displacement check</span>
</div>
<div id="energyCheck" class="check">
<span class="dot"></span>
<span>Work / energy check</span>
</div>
</div>
<div class="energy">
<h2 class="section-title">Ideal work balance</h2>
<div class="energy-row">
<span>Input work</span>
<strong id="inputWork">0 J</strong>
</div>
<div class="energy-row">
<span>Gravitational lift work</span>
<strong id="liftWork">0 J</strong>
</div>
<div class="energy-row">
<span>Kinetic energy</span>
<strong id="kineticEnergy">0 J</strong>
</div>
<div class="energy-row">
<span>Residual</span>
<strong id="energyResidual">0 J</strong>
</div>
</div>
</aside>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset camera</div>
<div id="labels">
<div id="effortLabel" class="world-label">Effort</div>
<div id="cargoLabel" class="world-label">Voxel cargo</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const G = 9.81;
const INITIAL_GROUP_Y = 2.85;
const TOP_PULLEY_Y = 9.15;
const EFFORT_X = 4.55;
const config = {
mass: 240,
force: 1500,
travel: 4,
target: 1.5,
ma: 2
};
const simulation = {
running: false,
done: false,
y: 0,
velocity: 0,
rope: 0,
stopLoss: 0
};
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 18, 35);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.64,
phi: 1.16,
radius: 16,
target: new THREE.Vector3(0, 3.7, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xc6eaff, 0x172031, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.1);
keyLight.position.set(5, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x43cfff, 70, 25, 2);
rimLight.position.set(-5, 6, -4);
scene.add(rimLight);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x0d1b2a,
roughness: 0.92,
metalness: 0.05
}),
frame: new THREE.MeshStandardMaterial({
color: 0x31485d,
roughness: 0.38,
metalness: 0.72
}),
frameEdge: new THREE.MeshStandardMaterial({
color: 0x567188,
roughness: 0.3,
metalness: 0.8
}),
pulley: new THREE.MeshStandardMaterial({
color: 0xb7cad8,
roughness: 0.28,
metalness: 0.82
}),
pulleyDark: new THREE.MeshStandardMaterial({
color: 0x233748,
roughness: 0.35,
metalness: 0.8
}),
rope: new THREE.MeshStandardMaterial({
color: 0xffce67,
roughness: 0.48,
metalness: 0.02
}),
effort: new THREE.MeshStandardMaterial({
color: 0xff855d,
roughness: 0.4,
metalness: 0.02
}),
pallet: new THREE.MeshStandardMaterial({
color: 0x6e5137,
roughness: 0.9
}),
strap: new THREE.MeshStandardMaterial({
color: 0x263747,
roughness: 0.72,
metalness: 0.25
})
};
const voxelMaterials = [
new THREE.MeshStandardMaterial({
color: 0xf5a623,
roughness: 0.73
}),
new THREE.MeshStandardMaterial({
color: 0xffc857,
roughness: 0.68
}),
new THREE.MeshStandardMaterial({
color: 0xf47d35,
roughness: 0.75
}),
new THREE.MeshStandardMaterial({
color: 0xe9b923,
roughness: 0.72
}),
new THREE.MeshStandardMaterial({
color: 0xffb13b,
roughness: 0.69
})
];
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 10);
const upVector = new THREE.Vector3(0, 1, 0);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(28, 28),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0x28465d, 0x142a3e);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const frameGroup = new THREE.Group();
scene.add(frameGroup);
addBox(
frameGroup,
new THREE.Vector3(10.5, 0.32, 0.48),
new THREE.Vector3(0, 10, 0),
materials.frame
);
for (const x of [-5.1, 5.1]) {
addBox(
frameGroup,
new THREE.Vector3(0.32, 10, 0.42),
new THREE.Vector3(x, 5, 0),
materials.frame
);
addBox(
frameGroup,
new THREE.Vector3(1.15, 0.18, 1.15),
new THREE.Vector3(x, 0.09, 0),
materials.frameEdge
);
}
addBox(
frameGroup,
new THREE.Vector3(10.5, 0.14, 0.18),
new THREE.Vector3(0, 8.75, 0),
materials.frameEdge
);
const movingGroup = new THREE.Group();
movingGroup.position.y = INITIAL_GROUP_Y;
scene.add(movingGroup);
const cargoGroup = new THREE.Group();
movingGroup.add(cargoGroup);
const voxelGeometry = new THREE.BoxGeometry(0.4, 0.4, 0.4);
const pitch = 0.425;
const cargoBottom = -2.65;
for (let x = 0; x < 6; x++) {
for (let y = 0; y < 4; y++) {
for (let z = 0; z < 5; z++) {
const colorIndex =
(x * 3 + y * 5 + z * 7 + x * z) % voxelMaterials.length;
const voxel = new THREE.Mesh(
voxelGeometry,
voxelMaterials[colorIndex]
);
voxel.position.set(
(x - 2.5) * pitch,
cargoBottom + (y + 0.5) * pitch,
(z - 2) * pitch
);
voxel.castShadow = true;
voxel.receiveShadow = true;
cargoGroup.add(voxel);
}
}
}
addBox(
cargoGroup,
new THREE.Vector3(2.75, 0.16, 2.25),
new THREE.Vector3(0, cargoBottom - 0.1, 0),
materials.pallet
);
for (const x of [-0.78, 0.78]) {
for (const z of [-1.07, 1.07]) {
addBox(
cargoGroup,
new THREE.Vector3(0.11, 1.02, 0.065),
new THREE.Vector3(x, -0.48, z),
materials.strap
);
}
}
const movingCrossbar = addBox(
movingGroup,
new THREE.Vector3(1, 0.19, 0.35),
new THREE.Vector3(0, 0, 0),
materials.frameEdge
);
const movingPulleyGroup = new THREE.Group();
movingGroup.add(movingPulleyGroup);
const rigGroup = new THREE.Group();
scene.add(rigGroup);
let supportRopes = [];
let topSheaves = [];
let movingSheaves = [];
let effortVertical = null;
let effortHandle = null;
let pulleyXs = [];
const effortArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(),
1,
0xff855d,
0.28,
0.16
);
const loadArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(),
1,
0x67e8a7,
0.28,
0.16
);
scene.add(effortArrow, loadArrow);
function setCylinderBetween(mesh, a, b, radius) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
upVector,
direction.normalize()
);
mesh.scale.set(radius, Math.max(length, 0.0001), radius);
}
function makeCylinder(parent, a, b, radius, material) {
const mesh = new THREE.Mesh(unitCylinder, material);
setCylinderBetween(mesh, a, b, radius);
parent.add(mesh);
return mesh;
}
function disposeUniqueGeometry(group) {
group.traverse(object => {
if (
object.geometry &&
object.geometry !== unitCylinder &&
object.geometry !== voxelGeometry
) {
object.geometry.dispose();
}
});
}
function buildRig() {
disposeUniqueGeometry(rigGroup);
disposeUniqueGeometry(movingPulleyGroup);
rigGroup.clear();
movingPulleyGroup.clear();
supportRopes = [];
topSheaves = [];
movingSheaves = [];
if (config.ma === 1) {
pulleyXs = [0];
} else if (config.ma === 2) {
pulleyXs = [-1.05, 1.05];
} else {
pulleyXs = [-2.25, -0.75, 0.75, 2.25];
}
for (const x of pulleyXs) {
const sheave = new THREE.Group();
sheave.position.set(x, TOP_PULLEY_Y, 0);
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.38, 0.085, 12, 36),
materials.pulley
);
wheel.castShadow = true;
sheave.add(wheel);
const innerRim = new THREE.Mesh(
new THREE.TorusGeometry(0.285, 0.035, 10, 32),
materials.pulleyDark
);
sheave.add(innerRim);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.26, 16),
materials.pulleyDark
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
sheave.add(hub);
rigGroup.add(sheave);
topSheaves.push(sheave);
const support = new THREE.Mesh(unitCylinder, materials.rope);
rigGroup.add(support);
supportRopes.push({ mesh: support, x });
const movingSheave = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.052, 10, 28),
materials.pulley
);
movingSheave.position.set(x, 0.18, 0);
movingSheave.castShadow = true;
movingPulleyGroup.add(movingSheave);
movingSheaves.push(movingSheave);
}
const span = Math.max(1, pulleyXs[pulleyXs.length - 1] - pulleyXs[0] + 0.7);
movingCrossbar.scale.x = span;
for (let i = 0; i < pulleyXs.length - 1; i++) {
makeCylinder(
rigGroup,
new THREE.Vector3(pulleyXs[i], TOP_PULLEY_Y, 0),
new THREE.Vector3(pulleyXs[i + 1], TOP_PULLEY_Y, 0),
0.024,
materials.rope
);
}
const rightmost = pulleyXs[pulleyXs.length - 1];
makeCylinder(
rigGroup,
new THREE.Vector3(rightmost, TOP_PULLEY_Y, 0),
new THREE.Vector3(EFFORT_X, TOP_PULLEY_Y, 0),
0.031,
materials.effort
);
effortVertical = new THREE.Mesh(unitCylinder, materials.effort);
rigGroup.add(effortVertical);
effortHandle = addBox(
rigGroup,
new THREE.Vector3(0.38, 0.24, 0.28),
new THREE.Vector3(EFFORT_X, TOP_PULLEY_Y - 0.4, 0),
materials.effort
);
}
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
if (projected.z < -1 || projected.z > 1) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateScene() {
movingGroup.position.y = INITIAL_GROUP_Y + simulation.y;
movingGroup.updateMatrixWorld(true);
for (const item of supportRopes) {
const bottom = movingGroup.localToWorld(
new THREE.Vector3(item.x, 0, 0)
);
const top = new THREE.Vector3(
item.x,
TOP_PULLEY_Y - 0.38,
0
);
setCylinderBetween(item.mesh, top, bottom, 0.026);
}
for (const sheave of topSheaves) {
sheave.rotation.z = -simulation.rope / 0.38;
}
for (const sheave of movingSheaves) {
sheave.rotation.z =
-simulation.rope / Math.max(0.18 * config.ma, 0.001);
}
const effortEndY = TOP_PULLEY_Y - 0.4 - simulation.rope;
setCylinderBetween(
effortVertical,
new THREE.Vector3(EFFORT_X, TOP_PULLEY_Y, 0),
new THREE.Vector3(EFFORT_X, effortEndY, 0),
0.031
);
effortHandle.position.y = effortEndY;
const effortLength = 0.5 + (config.force / 6000) * 1.35;
effortArrow.position.set(
EFFORT_X + 0.34,
effortEndY + effortLength + 0.12,
0
);
effortArrow.setLength(effortLength, 0.28, 0.16);
const cargoBottomWorld = movingGroup.position.y + cargoBottom;
const loadLength = 0.65 + (config.mass / 500) * 1.05;
loadArrow.position.set(
-3.25,
cargoBottomWorld + 0.12,
0
);
loadArrow.setLength(loadLength, 0.28, 0.16);
$("effortLabel").textContent =
`Effort ${formatForce(config.force)}`;
$("cargoLabel").textContent =
`${config.mass} kg · 6 × 4 × 5 voxels`;
placeLabel(
$("effortLabel"),
new THREE.Vector3(EFFORT_X + 0.2, effortEndY, 0)
);
placeLabel(
$("cargoLabel"),
movingGroup.localToWorld(
new THREE.Vector3(-0.4, -0.64, 0)
)
);
}
function formatForce(newtons) {
if (newtons >= 1000) {
return `${(newtons / 1000).toFixed(2)} kN`;
}
return `${newtons.toFixed(0)} N`;
}
function setStatus(kind, title, detail) {
$("status").dataset.kind = kind;
$("statusTitle").textContent = title;
$("statusDetail").textContent = detail;
}
function setCheck(id, state, text) {
const element = $(id);
element.className = `check ${state}`;
element.innerHTML =
`<span class="dot"></span><span>${text}</span>`;
}
function updateReadouts() {
const weight = config.mass * G;
const required = weight / config.ma;
const maximumRise = config.travel / config.ma;
const requiredRope = config.ma * config.target;
const netForce = config.ma * config.force - weight;
const travelOK = requiredRope <= config.travel + 0.0001;
const inputWork = config.force * simulation.rope;
const liftWork = weight * simulation.y;
const kinetic = 0.5 * config.mass * simulation.velocity ** 2;
const residual =
inputWork - liftWork - kinetic - simulation.stopLoss;
$("requiredForce").textContent = formatForce(required);
$("maximumRise").textContent = `${maximumRise.toFixed(2)} m`;
$("ropeNeeded").textContent = `${requiredRope.toFixed(2)} m`;
$("ropeUsed").textContent = `${simulation.rope.toFixed(2)} m`;
$("cargoRise").textContent = `${simulation.y.toFixed(2)} m`;
if (simulation.y > 0.002) {
const observed = simulation.rope / simulation.y;
$("observedRatio").textContent =
`${observed.toFixed(3)} : 1`;
} else {
$("observedRatio").textContent = "—";
}
$("inputWork").textContent = `${formatEnergy(inputWork)}`;
$("liftWork").textContent = `${formatEnergy(liftWork)}`;
$("kineticEnergy").textContent = `${formatEnergy(kinetic)}`;
$("energyResidual").textContent = `${formatEnergy(residual)}`;
if (config.force > required + 1) {
setCheck(
"forceCheck",
"pass",
`Force passes: ${formatForce(config.force)} exceeds the ${formatForce(required)} minimum.`
);
} else if (Math.abs(config.force - required) <= 1) {
setCheck(
"forceCheck",
"warn",
`Force is balanced at ${formatForce(required)}; the load can be supported but will not accelerate.`
);
} else {
setCheck(
"forceCheck",
"fail",
`Force fails: ${formatForce(config.force)} is below the ${formatForce(required)} minimum.`
);
}
if (travelOK) {
setCheck(
"travelCheck",
"pass",
`Travel passes: ${requiredRope.toFixed(2)} m of rope is required and ${config.travel.toFixed(2)} m is available.`
);
} else {
setCheck(
"travelCheck",
"fail",
`Travel fails: ${requiredRope.toFixed(2)} m of rope is required, but only ${config.travel.toFixed(2)} m is available.`
);
}
if (simulation.y > 0.002) {
const observed = simulation.rope / simulation.y;
const ratioOK =
Math.abs(observed - config.ma) < 0.002 * config.ma;
setCheck(
"ratioCheck",
ratioOK ? "pass" : "fail",
ratioOK
? `Displacement passes: measured rope travel divided by cargo rise is ${observed.toFixed(3)}, matching ${config.ma}:1.`
: `Displacement mismatch: measured ratio is ${observed.toFixed(3)} instead of ${config.ma}:1.`
);
} else {
setCheck(
"ratioCheck",
"warn",
"Displacement check awaits measurable cargo motion."
);
}
const energyTolerance = Math.max(
1,
0.002 * Math.max(inputWork, liftWork, 1)
);
const energyOK = Math.abs(residual) <= energyTolerance;
if (simulation.done && simulation.stopLoss > 0) {
setCheck(
"energyCheck",
"pass",
`Energy balances: ${formatEnergy(simulation.stopLoss)} of final kinetic energy is absorbed by the ideal end stop.`
);
} else if (inputWork === 0 && liftWork === 0) {
setCheck(
"energyCheck",
"warn",
"Work check awaits motion. Friction and moving pulley mass are excluded."
);
} else {
setCheck(
"energyCheck",
energyOK ? "pass" : "fail",
energyOK
? "Energy passes: input work minus gravitational work equals the cargo's kinetic energy."
: `Energy mismatch: residual is ${formatEnergy(residual)}.`
);
}
if (simulation.done) {
if (travelOK) {
setStatus(
"success",
"Target reached",
`The cargo rose ${simulation.y.toFixed(2)} m using ${simulation.rope.toFixed(2)} m of rope.`
);
} else {
setStatus(
"danger",
"Rope limit reached",
`The cargo rose only ${simulation.y.toFixed(2)} m. More rope travel is required for the target.`
);
}
} else if (simulation.running) {
setStatus(
"running",
travelOK ? "Lifting cargo" : "Rope-limited trial",
travelOK
? `Net upward force is ${formatForce(Math.max(0, netForce))}.`
: "The available rope cannot reach the requested target; the trial will stop at the rope limit."
);
} else if (config.force < required) {
setStatus(
"danger",
"Insufficient effort",
`At least ${formatForce(required)} is required. The rope cannot pull the cargo upward.`
);
} else if (Math.abs(config.force - required) <= 1) {
setStatus(
"warn",
"Balanced rig",
"The effort exactly balances the load. Apply slightly more force to accelerate the cargo."
);
} else if (!travelOK) {
setStatus(
"warn",
"Rope budget is too small",
`The force is sufficient, but ${config.ma}:1 displacement requires ${requiredRope.toFixed(2)} m of rope.`
);
} else {
setStatus(
"ready",
"Ready to lift",
`Force margin is ${formatForce(netForce)}. The requested target is within the rope budget.`
);
}
}
function formatEnergy(joules) {
const absolute = Math.abs(joules);
if (absolute >= 1000) {
return `${(joules / 1000).toFixed(2)} kJ`;
}
return `${joules.toFixed(1)} J`;
}
function resetSimulation() {
simulation.running = false;
simulation.done = false;
simulation.y = 0;
simulation.velocity = 0;
simulation.rope = 0;
simulation.stopLoss = 0;
$("toggleLift").textContent = "Start lift";
updateReadouts();
}
function stepSimulation(dt) {
const weight = config.mass * G;
const acceleration =
(config.ma * config.force - weight) / config.mass;
const goalY = Math.min(
config.target,
config.travel / config.ma
);
const remaining = goalY - simulation.y;
if (remaining <= 0.000001) {
simulation.done = true;
simulation.running = false;
$("toggleLift").textContent = "Lift complete";
return;
}
// Solve the constant-acceleration boundary time exactly.
const discriminant =
simulation.velocity ** 2 + 2 * acceleration * remaining;
if (discriminant >= 0) {
const boundaryTime =
(-simulation.velocity + Math.sqrt(discriminant)) /
acceleration;
const boundaryVelocity =
simulation.velocity + acceleration * boundaryTime;
simulation.y = goalY;
simulation.rope = config.ma * simulation.y;
simulation.stopLoss +=
0.5 * config.mass * boundaryVelocity ** 2;
simulation.velocity = 0;
simulation.running = false;
simulation.done = true;
const reachedTarget =
Math.abs(goalY - config.target) < 0.000001;
$("toggleLift").textContent = reachedTarget
? "Lift complete"
: "Rope limit reached";
return;
}
const displacement =
simulation.velocity * dt +
0.5 * acceleration * dt * dt;
const newVelocity =
simulation.velocity + acceleration * dt;
simulation.y += displacement;
simulation.velocity = newVelocity;
simulation.rope = config.ma * simulation.y;
}
function syncControlLabels() {
$("massValue").textContent = `${config.mass.toFixed(0)} kg`;
$("forceValue").textContent = formatForce(config.force);
$("travelValue").textContent = `${config.travel.toFixed(2)} m`;
$("targetValue").textContent = `${config.target.toFixed(2)} m`;
for (const key of ["mass", "force", "travel", "target"]) {
const input = $(`${key}Range`);
const fraction =
(Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min));
input.style.setProperty(
"--fill",
`${Math.max(0, Math.min(1, fraction)) * 100}%`
);
}
}
for (const key of ["mass", "force", "travel", "target"]) {
$(`${key}Range`).addEventListener("input", event => {
config[key] = Number(event.target.value);
syncControlLabels();
resetSimulation();
});
}
document.querySelectorAll("[data-ma]").forEach(button => {
button.addEventListener("click", () => {
config.ma = Number(button.dataset.ma);
document.querySelectorAll("[data-ma]").forEach(other => {
other.classList.toggle(
"active",
Number(other.dataset.ma) === config.ma
);
});
buildRig();
resetSimulation();
});
});
$("toggleLift").addEventListener("click", () => {
if (simulation.running) {
simulation.running = false;
$("toggleLift").textContent = "Resume lift";
updateReadouts();
return;
}
if (simulation.done) {
resetSimulation();
}
const required = config.mass * G / config.ma;
if (config.force < required) {
setStatus(
"danger",
"Lift blocked",
`The applied effort is below ${formatForce(required)}, so the cargo cannot be lifted.`
);
return;
}
if (config.force === required) {
setStatus(
"warn",
"Balanced rig",
"Exactly the required force is applied. Add a small force margin to accelerate upward."
);
return;
}
simulation.running = true;
$("toggleLift").textContent = "Pause lift";
});
$("resetLift").addEventListener("click", resetSimulation);
// Camera controls are implemented directly, without Three.js addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.006,
0.35,
1.48
);
updateCamera();
});
canvas.addEventListener("pointerup", event => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
9,
26
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.theta = 0.64;
orbit.phi = 1.16;
orbit.radius = 16;
orbit.target.set(0, 3.7, 0);
updateCamera();
});
canvas.addEventListener("contextmenu", event => {
event.preventDefault();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
buildRig();
syncControlLabels();
resetSimulation();
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
if (simulation.running) {
stepSimulation(dt);
}
updateScene();
updateReadouts();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```