Prompt specification
Build or customize the Three.js 3D scene "Pulley Lift With a Fixed Pull-Travel Stop" 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: Pulley Lift With a Fixed Pull-Travel Stop
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pulley-lift-with-a-fixed-pull-travel-stop-x3494
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this cutaway scene: Create a small movable-pulley lift puzzle with a hard stop on the free rope end. Predict whether the load reaches a latch while enforcing constant rope length.
Working Three.js Starter (pulley-lift-with-a-fixed-pull-travel-stop-x3494):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Movable-Pulley Lift — Cutaway Rig</title>
<style>
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:#0a0e12;overflow:hidden;
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:#cfe3ef}
#app{position:fixed;inset:0}
#app canvas{display:block;touch-action:none}
#hud{position:fixed;left:14px;top:14px;width:336px;pointer-events:none;z-index:5}
#right{position:fixed;right:14px;top:14px;width:304px;pointer-events:none;z-index:5}
.panel{background:rgba(10,16,22,.86);border:1px solid #22323f;border-radius:10px;
padding:10px 12px;margin-bottom:10px;backdrop-filter:blur(7px);
box-shadow:0 8px 26px rgba(0,0,0,.45)}
h1{font-size:12px;letter-spacing:.14em;margin:0 0 9px;color:#79d5ff;text-transform:uppercase}
h2{font-size:11px;letter-spacing:.12em;margin:0 0 8px;color:#79d5ff;text-transform:uppercase}
.row{display:flex;justify-content:space-between;gap:10px;font-size:11.5px;padding:2.5px 0;color:#93a9ba}
.row b{color:#eaf5fc;font-weight:600}
.note{font-size:10.5px;line-height:1.5;color:#7f95a6;margin-top:8px}
.verdict{margin-top:9px;padding:8px 10px;border-radius:7px;font-size:12px;line-height:1.4}
.no{background:rgba(170,40,40,.20);border:1px solid #8a2b2b;color:#ffb3b3}
.yes{background:rgba(25,150,85,.20);border:1px solid #2a7f57;color:#a9f5c8}
.ctl{display:flex;gap:7px;flex-wrap:wrap;align-items:center;pointer-events:auto}
button{font:inherit;font-size:11.5px;background:#152532;color:#cfe3ef;border:1px solid #2c4457;
border-radius:6px;padding:7px 11px;cursor:pointer}
button:hover{background:#1e3446}
button:active{background:#254459}
input[type=range]{width:100%;pointer-events:auto;accent-color:#4fb8ff}
label.chk{font-size:11px;display:flex;gap:6px;align-items:center;pointer-events:auto;cursor:pointer}
#status{position:fixed;left:50%;bottom:12px;transform:translateX(-50%);z-index:5;pointer-events:none;
background:rgba(10,16,22,.86);border:1px solid #22323f;border-radius:8px;padding:7px 14px;
font-size:11.5px;color:#a9c2d2;white-space:nowrap}
#status b{color:#eaf5fc}
canvas.plot{width:280px;height:168px;display:block;background:#0b1117;border:1px solid #1b2833;border-radius:6px}
</style>
</head>
<body>
<div id="app"></div>
<div id="hud">
<div class="panel">
<h1>Movable-Pulley Lift · Cutaway Rig</h1>
<div class="row"><span>Load start (pulley axis)</span><b>0.900 m</b></div>
<div class="row"><span>Latch target height</span><b>1.450 m</b></div>
<div class="row"><span>Mechanical advantage</span><b>2.0 (rope in / load out)</b></div>
<div class="row"><span>Pull needed to latch</span><b>1.100 m</b></div>
<div class="row"><span>Pull allowed by hard stop</span><b id="allowed">0.790 m</b></div>
<div class="row"><span>Max reachable load height</span><b id="maxh">1.295 m</b></div>
<div class="row"><span>Shortfall at latch</span><b id="short">0.155 m</b></div>
<div class="verdict no" id="verdict">PREDICTION: NO — the load stops short of the latch.</div>
<div class="verdict" id="actual" style="display:none"></div>
</div>
<div class="panel">
<h2>Test</h2>
<div class="ctl">
<button id="pull">HOLD TO PULL</button>
<button id="reset">RESET</button>
<button id="remove">REMOVE STOP</button>
<label class="chk"><input type="checkbox" id="labels" checked> labels</label>
</div>
<div class="note">Hard-stop height (top of pad): <b id="stopv">0.55 m</b></div>
<input type="range" id="stop" min="0" max="1.30" step="0.01" value="0.55">
<div class="note">Rope is fixed-length, so every 1 m of pull raises the load only 0.5 m
(MA 2). Pull the handle (drag it) or hold <b>HOLD TO PULL</b>; the handle cannot pass
through the hard stop.</div>
</div>
</div>
<div id="right">
<div class="panel">
<h2>Pull vs. load height</h2>
<canvas class="plot" id="plot" width="560" height="336"></canvas>
<div class="note">Blue: rope constraint y = y₀ + s/2. Green: latch height 1.45 m (needs s = 1.10 m).
Red: pull the hard stop permits. The intersection of red and green shows the failure.</div>
</div>
</div>
<div id="status">
rope length L = <b id="L">—</b> m (constant) | pull s = <b id="s">0.000</b> m |
load axis y = <b id="y">0.900</b> m | MA = <b>2.0</b> | latch = <b id="st">open</b>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ───────────────────────── CONFIG / GEOMETRY ─────────────────────────
Rope path (single plane, z = 0):
anchor A (x = MX-RM, y = TOP) ↓
movable pulley (x = MX, y = my) ← wraps UNDER, radius RM
↑ fixed pulley (x = FIX_X, y = TOP) ← wraps OVER, radius RF
↓ free end (x = FREE_X, y = hy) → handle → hard stop
*/
const C = {
TOP: 3.00, // anchor & fixed-pulley axle height
MY0: 0.90, // movable-pulley axis height at start
HY0: 1.60, // free rope end attach height at start
RM: 0.22, // movable pulley radius
RF: 0.18, // fixed (redirect) pulley radius
MX: 0.00, // movable pulley x
LATCH_Y: 1.45, // target pulley-axis height that arms the latch
PIN_DY: -0.32, // latch pin offset from pulley axis (load-local)
FOOT: 0.26, // handle foot depth below the rope end
FLOOR: 0.00
};
const ANCHOR_X = C.MX - C.RM; // -0.22
const FIX_X = C.MX + C.RM + C.RF; // 0.40
const FREE_X = FIX_X + C.RF; // 0.58
const CATCH_Y = C.LATCH_Y + C.PIN_DY; // 1.13 (latch catch height)
/* Constant rope length:
L = (TOP-my) + π·RM + (TOP-my) + π·RF + (TOP-hy)
= 2·(TOP-my) + π(RM+RF) + (TOP-hy)
Pulling the free end down by s ⇒ hy = HY0 - s, and to keep L fixed
we MUST have my = MY0 + s/2. (MA = 2: two rope segments pay out per unit lift.) */
const ropeLen = (my, hy) => 2 * (C.TOP - my) + Math.PI * (C.RM + C.RF) + (C.TOP - hy);
const L0 = ropeLen(C.MY0, C.HY0);
const REQUIRED = 2 * (C.LATCH_Y - C.MY0); // 1.10 m of pull needed to latch
/* ───────────────────────── STATE ───────────────────────── */
let s = 0; // free-end pull distance (m)
let stopY = 0.55; // hard-stop pad top height (m)
let latched = false, sLatch = 0, tested = false;
const sMaxNow = () => Math.min(Math.max(0, (C.HY0 - C.FOOT) - stopY),
(C.HY0 - C.FOOT) - C.FLOOR);
/* ───────────────────────── RENDERER / SCENE ───────────────────────── */
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.getElementById('app').appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a0e12);
scene.fog = new THREE.Fog(0x0a0e12, 14, 30);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);
const cam = { r: 6.6, theta: 0.60, phi: 1.14, target: new THREE.Vector3(0, 1.55, 0) };
function updateCam() {
cam.phi = THREE.MathUtils.clamp(cam.phi, 0.22, Math.PI / 2 - 0.06);
cam.r = THREE.MathUtils.clamp(cam.r, 3.2, 15);
const x = cam.target.x + cam.r * Math.sin(cam.phi) * Math.sin(cam.theta);
const y = cam.target.y + cam.r * Math.cos(cam.phi);
const z = cam.target.z + cam.r * Math.sin(cam.phi) * Math.cos(cam.theta);
camera.position.set(x, y, z);
camera.lookAt(cam.target);
}
updateCam();
scene.add(new THREE.HemisphereLight(0xbcd7ee, 0x1d242b, 0.55));
const key = new THREE.DirectionalLight(0xffffff, 1.15);
key.position.set(4.5, 7.5, 5.5); key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6; key.shadow.camera.right = 6;
key.shadow.camera.top = 7; key.shadow.camera.bottom = -3;
key.shadow.camera.near = 1; key.shadow.camera.far = 22;
key.shadow.bias = -0.0008;
scene.add(key);
const fill = new THREE.DirectionalLight(0x8fc7ff, 0.35); fill.position.set(-5, 3, 4); scene.add(fill);
/* ───────────────────────── MATERIALS ───────────────────────── */
const M = {
shell: new THREE.MeshStandardMaterial({ color: 0x33434f, metalness: .35, roughness: .62 }),
shellIn:new THREE.MeshStandardMaterial({ color: 0x1b2731, metalness: .20, roughness: .88 }),
cut: new THREE.MeshStandardMaterial({ color: 0xff7a29, emissive: 0x6d2800, emissiveIntensity: .55, roughness: .55 }),
steel: new THREE.MeshStandardMaterial({ color: 0xaeb9c4, metalness: .88, roughness: .28 }),
dark: new THREE.MeshStandardMaterial({ color: 0x161b21, metalness: .55, roughness: .5 }),
rope: new THREE.MeshStandardMaterial({ color: 0xd9c08a, roughness: .95 }),
crate: new THREE.MeshStandardMaterial({ color: 0xb07c46, roughness: .85 }),
band: new THREE.MeshStandardMaterial({ color: 0x5b6570, metalness: .8, roughness: .4 }),
latch: new THREE.MeshStandardMaterial({ color: 0xd23b3b, metalness: .4, roughness: .42 }),
stop: new THREE.MeshStandardMaterial({ color: 0xffb020, metalness: .3, roughness: .45 }),
green: new THREE.MeshStandardMaterial({ color: 0x37d67a, emissive: 0x0f6b35, emissiveIntensity: .8 })
};
/* ───────────────────────── HOUSING (CUTAWAY) ───────────────────────── */
const G = new THREE.Group(); scene.add(G);
function box(w, h, d, mat, x, y, z, parent = G) {
const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
m.position.set(x, y, z); m.castShadow = true; m.receiveShadow = true; parent.add(m); return m;
}
function cyl(r, h, mat, x, y, z, axis = 'y', parent = G) {
const m = new THREE.Mesh(new THREE.CylinderGeometry(r, r, h, 20), mat);
if (axis === 'z') m.rotation.x = Math.PI / 2;
if (axis === 'x') m.rotation.z = Math.PI / 2;
m.position.set(x, y, z); m.castShadow = true; m.receiveShadow = true; parent.add(m); return m;
}
// base slab + floor plate
box(3.0, 0.18, 2.0, M.shell, 0, -0.09, 0);
box(2.76, 0.03, 1.8, M.dark, 0, 0.015, -0.05);
// back wall + inner face
box(3.0, 3.5, 0.12, M.shell, 0, 1.75, -0.95);
box(2.76, 3.3, 0.02, M.shellIn, 0, 1.75, -0.88);
// left wall (full depth)
box(0.12, 3.5, 1.95, M.shell, -1.44, 1.75, 0);
// right wall — SECTIONED: back half only
box(0.12, 3.5, 0.90, M.shell, 1.44, 1.75, -0.50);
// roof — SECTIONED: back half only
box(3.0, 0.12, 0.90, M.shell, 0, 3.44, -0.50);
// orange section-cut faces
box(0.14, 3.5, 0.03, M.cut, 1.44, 1.75, -0.035);
box(3.0, 0.14, 0.03, M.cut, 0, 3.44, -0.035);
box(0.14, 3.5, 0.03, M.cut, -1.44, 1.75, 0.975);
box(3.0, 0.19, 0.03, M.cut, 0, -0.09, 1.00);
// ground + grid
const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({ color: 0x0d1216, roughness: 1 }));
ground.rotation.x = -Math.PI / 2; ground.position.y = -0.19; ground.receiveShadow = true; scene.add(ground);
const grid = new THREE.GridHelper(40, 40, 0x243440, 0x16212a);
grid.position.y = -0.185; scene.add(grid);
/* ───────────────────────── FRAME / RIG ───────────────────────── */
// guide rails (behind the rope plane)
cyl(0.035, 3.10, M.steel, -0.45, 1.62, -0.35);
cyl(0.035, 3.10, M.steel, 0.45, 1.62, -0.35);
// header bar + hangers
box(2.40, 0.14, 0.20, M.steel, 0, 3.30, -0.35);
box(0.10, 0.30, 0.34, M.steel, ANCHOR_X, 3.12, -0.18);
cyl(0.03, 0.30, M.dark, ANCHOR_X, C.TOP, 0, 'z'); // anchor shackle pin
box(0.14, 0.30, 0.30, M.steel, FIX_X, 3.18, -0.18); // fixed-pulley hanger
// target-height marker (green)
box(0.86, 0.012, 0.012, M.green, -0.02, C.LATCH_Y, -0.35);
box(0.10, 0.14, 0.03, M.green, -0.45, C.LATCH_Y, -0.35);
// ── fixed (redirect) pulley
const fixPulley = new THREE.Group(); fixPulley.position.set(FIX_X, C.TOP, 0); G.add(fixPulley);
const fw = cyl(C.RF, 0.11, M.steel, 0, 0, 0, 'z', fixPulley);
fw.geometry = new THREE.CylinderGeometry(C.RF, C.RF, 0.11, 28);
const fr1 = new THREE.Mesh(new THREE.TorusGeometry(C.RF - 0.012, 0.022, 10, 30), M.dark);
fr1.position.z = 0.052; fixPulley.add(fr1);
const fr2 = fr1.clone(); fr2.position.z = -0.052; fixPulley.add(fr2);
cyl(0.045, 0.20, M.dark, 0, 0, 0, 'z', fixPulley);
// ── movable pulley + load carriage (group origin = pulley axis)
const load = new THREE.Group(); G.add(load);
const mw = new THREE.Mesh(new THREE.CylinderGeometry(C.RM, C.RM, 0.11, 28), M.steel);
mw.rotation.x = Math.PI / 2; mw.castShadow = true; load.add(mw);
const mr1 = new THREE.Mesh(new THREE.TorusGeometry(C.RM - 0.012, 0.022, 10, 30), M.dark);
mr1.position.z = 0.052; load.add(mr1);
const mr2 = mr1.clone(); mr2.position.z = -0.052; load.add(mr2);
cyl(0.05, 0.22, M.dark, 0, 0, 0, 'z', load);
// yoke plates down to the crate
box(0.06, 0.32, 0.03, M.steel, 0, -0.15, 0.085, load);
box(0.06, 0.32, 0.03, M.steel, 0, -0.15, -0.085, load);
// crate
box(0.72, 0.44, 0.62, M.crate, 0, -0.52, 0, load);
box(0.74, 0.04, 0.64, M.band, 0, -0.34, 0, load);
box(0.74, 0.04, 0.64, M.band, 0, -0.70, 0, load);
for (let i = -2; i <= 2; i++) box(0.03, 0.42, 0.64, M.band, i * 0.14, -0.52, 0, load);
// carriage blocks riding the rails
box(0.10, 0.16, 0.10, M.dark, -0.45, -0.34, -0.35, load);
box(0.10, 0.16, 0.10, M.dark, 0.45, -0.34, -0.35, load);
// latch pin (sticks out to the left, below the crate top)
cyl(0.028, 0.20, M.steel, -0.42, C.PIN_DY, 0, 'x', load);
// ── free rope end + handle
const handle = new THREE.Group(); G.add(handle);
const eye = new THREE.Mesh(new THREE.TorusGeometry(0.05, 0.016, 10, 22), M.dark);
handle.add(eye);
box(0.05, 0.20, 0.05, M.steel, 0, -0.12, 0, handle);
box(0.16, 0.04, 0.16, M.dark, 0, -0.24, 0, handle); // foot (rests on the stop)
const grip = cyl(0.028, 0.22, M.latch, 0, -0.09, 0, 'z', handle);
// ── hard stop (moves with the slider)
const stopG = new THREE.Group(); G.add(stopG);
box(0.16, 0.07, 1.00, M.steel, 0.62, -0.035, -0.55, stopG); // beam out of the back wall
box(0.22, 0.06, 0.26, M.stop, 0.62, -0.030, 0.00, stopG); // pad (top = stopY)
box(0.05, 0.02, 0.26, M.dark, 0.55, 0.002, 0.00, stopG); // hazard stripes
box(0.05, 0.02, 0.26, M.dark, 0.69, 0.002, 0.00, stopG);
box(0.12, 0.16, 0.12, M.steel, 0.62, -0.12, -0.05, stopG);
// ── latch mechanism (left wall)
box(0.60, 0.08, 0.16, M.steel, -1.08, CATCH_Y + 0.09, 0);
box(0.08, 0.16, 0.16, M.steel, -0.80, CATCH_Y + 0.02, 0);
cyl(0.03, 0.22, M.dark, -0.80, CATCH_Y, 0, 'z');
const arm = new THREE.Group(); arm.position.set(-0.80, CATCH_Y, 0); G.add(arm);
box(0.32, 0.07, 0.10, M.latch, 0.16, 0, 0, arm);
box(0.06, 0.12, 0.10, M.latch, 0.32, -0.04, 0, arm); // hook tip
arm.rotation.z = 1.55; // OPEN (pointing up)
// ── rope (rebuilt whenever geometry changes)
const rope = new THREE.Mesh(new THREE.BufferGeometry(), M.rope);
rope.castShadow = true; scene.add(rope);
function buildRope(my, hy) {
const pts = [];
pts.push(new THREE.Vector3(ANCHOR_X, C.TOP, 0));
pts.push(new THREE.Vector3(ANCHOR_X, my, 0));
const N1 = 14;
for (let i = 1; i <= N1; i++) { // under the movable pulley
const a = Math.PI + i * Math.PI / N1;
pts.push(new THREE.Vector3(C.MX + Math.cos(a) * C.RM, my + Math.sin(a) * C.RM, 0));
}
pts.push(new THREE.Vector3(FIX_X - C.RF, C.TOP, 0));
const N2 = 12;
for (let i = 1; i <= N2; i++) { // over the fixed pulley
const a = Math.PI - i * Math.PI / N2;
pts.push(new THREE.Vector3(FIX_X + Math.cos(a) * C.RF, C.TOP + Math.sin(a) * C.RF, 0));
}
pts.push(new THREE.Vector3(FREE_X, hy, 0));
const curve = new THREE.CatmullRomCurve3(pts, false, 'centripetal');
rope.geometry.dispose();
rope.geometry = new THREE.TubeGeometry(curve, 96, 0.032, 8, false);
}
/* ───────────────────────── LABELS ───────────────────────── */
function makeLabel(text, color = '#a9e2ff', k = 1) {
const cv = document.createElement('canvas'), ctx = cv.getContext('2d');
ctx.font = '600 42px ui-monospace, Menlo, monospace';
const w = Math.ceil(ctx.measureText(text).width) + 30, h = 60;
cv.width = w; cv.height = h;
const c = cv.getContext('2d');
c.font = '600 42px ui-monospace, Menlo, monospace';
c.fillStyle = 'rgba(8,14,20,.75)';
c.beginPath(); c.roundRect(0, 0, w, h, 12); c.fill();
c.strokeStyle = color; c.lineWidth = 2.5; c.stroke();
c.fillStyle = color; c.textBaseline = 'middle';
c.fillText(text, 15, h / 2 + 2);
const tex = new THREE.CanvasTexture(cv); tex.colorSpace = THREE.SRGBColorSpace;
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, transparent: true, depthTest: false }));
sp.scale.set(w / 60 * 0.30 * k, h / 60 * 0.30 * k, 1);
sp.renderOrder = 10;
return sp;
}
const labelG = new THREE.Group(); scene.add(labelG);
function addLabel(text, x, y, z, color) { const s = makeLabel(text, color); s.position.set(x, y, z); labelG.add(s); return s; }
addLabel('FIXED ANCHOR', ANCHOR_X, 3.45, 0.05);
addLabel('FIXED PULLEY (redirect)', FIX_X, 3.62, 0.05, '#c9d7e2');
const lMov = addLabel('MOVABLE PULLEY · MA 2', 0, 1.30, 0.05, '#8ff0c4');
const lStop = addLabel('HARD STOP', 1.02, 0.80, 0.05, '#ffc46b');
const lLatch = addLabel('LATCH', -0.95, 1.42, 0.05, '#ff9b9b');
addLabel('TARGET 1.45 m', -0.75, 1.60, -0.30, '#8ff0c4');
/* ───────────────────────── INTERACTION ───────────────────────── */
const ray = new THREE.Raycaster(), ndc = new THREE.Vector2();
const planeZ0 = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const canvas = renderer.domElement;
let mode = 'orbit', drag = { x: 0, y: 0 }, pullRef = { s: 0, y: 0 }, auto = false;
function planeY(e) {
ndc.set((e.clientX / innerWidth) * 2 - 1, -(e.clientY / innerHeight) * 2 + 1);
ray.setFromCamera(ndc, camera);
const p = new THREE.Vector3();
return ray.ray.intersectPlane(planeZ0, p) ? p.y : null;
}
function hitsHandle(e) {
ndc.set((e.clientX / innerWidth) * 2 - 1, -(e.clientY / innerHeight) * 2 + 1);
ray.setFromCamera(ndc, camera);
return ray.intersectObject(handle, true).length > 0;
}
canvas.addEventListener('pointerdown', e => {
if (hitsHandle(e)) {
mode = 'pull'; pullRef.s = s; const y = planeY(e); if (y !== null) pullRef.y = y;
canvas.setPointerCapture(e.pointerId);
} else {
mode = 'orbit'; drag.x = e.clientX; drag.y = e.clientY;
canvas.setPointerCapture(e.pointerId);
}
});
canvas.addEventListener('pointermove', e => {
if (mode === 'orbit') {
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
drag.x = e.clientX; drag.y = e.clientY;
cam.theta -= dx * 0.006; cam.phi -= dy * 0.005;
} else if (mode === 'pull') {
const y = planeY(e);
if (y !== null) {
let ns = pullRef.s + (pullRef.y - y);
ns = THREE.MathUtils.clamp(ns, 0, sMaxNow());
if (ns > s + 1e-4) tested = true;
s = ns;
}
} else {
canvas.style.cursor = hitsHandle(e) ? 'ns-resize' : 'grab';
}
});
const endDrag = e => { mode = 'orbit'; try { canvas.releasePointerCapture(e.pointerId); } catch (_) {} };
canvas.addEventListener('pointerup', endDrag);
canvas.addEventListener('pointercancel', endDrag);
canvas.addEventListener('wheel', e => { cam.r *= 1 + e.deltaY * 0.0012; e.preventDefault(); }, { passive: false });
/* ───────────────────────── HUD ───────────────────────── */
const $ = id => document.getElementById(id);
const el = {
allowed: $('allowed'), maxh: $('maxh'), short: $('short'), verdict: $('verdict'), actual: $('actual'),
L: $('L'), s: $('s'), y: $('y'), st: $('st'), stopv: $('stopv'), slider: $('stop')
};
const pctx = $('plot').getContext('2d');
function drawPlot() {
const W = 560, H = 336, c = pctx;
c.setTransform(1, 0, 0, 1, 0, 0); c.clearRect(0, 0, W, H);
const pad = 62, x0 = pad, y0 = H - 52, x1 = W - 26, y1 = 24;
const sMaxP = 1.4, hMin = 0.80, hMax = 1.70;
const sx = v => x0 + (v / sMaxP) * (x1 - x0);
const sy = v => y0 - ((v - hMin) / (hMax - hMin)) * (y0 - y1);
// grid + axes
c.strokeStyle = '#18242e'; c.lineWidth = 2;
for (let v = 0; v <= 1.4 + 1e-6; v += 0.2) { c.beginPath(); c.moveTo(sx(v), y1); c.lineTo(sx(v), y0); c.stroke(); }
for (let v = 0.8; v <= 1.701; v += 0.15) { c.beginPath(); c.moveTo(x0, sy(v)); c.lineTo(x1, sy(v)); c.stroke(); }
c.strokeStyle = '#33485a'; c.lineWidth = 3;
c.beginPath(); c.moveTo(x0, y0); c.lineTo(x1, y0); c.moveTo(x0, y0); c.lineTo(x0, y1); c.stroke();
c.fillStyle = '#7f95a6'; c.font = '600 20px ui-monospace, monospace';
c.textAlign = 'center'; c.fillText('pull s (m)', (x0 + x1) / 2, H - 12);
c.save(); c.translate(22, (y0 + y1) / 2); c.rotate(-Math.PI / 2);
c.fillText('load height y (m)', 0, 0); c.restore();
// forbidden region (beyond the hard stop)
const sm = sMaxNow();
c.fillStyle = 'rgba(190,50,50,.18)';
c.fillRect(sx(sm), y1, x1 - sx(sm), y0 - y1);
// rope constraint
c.strokeStyle = '#4fb8ff'; c.lineWidth = 4;
c.beginPath(); c.moveTo(sx(0), sy(C.MY0)); c.lineTo(sx(sMaxP), sy(C.MY0 + sMaxP / 2)); c.stroke();
// latch height
c.setLineDash([10, 8]); c.strokeStyle = '#37d67a'; c.lineWidth = 3;
c.beginPath(); c.moveTo(x0, sy(C.LATCH_Y)); c.lineTo(x1, sy(C.LATCH_Y)); c.stroke();
c.setLineDash([]);
// stop limit
c.strokeStyle = '#ff6b5e'; c.lineWidth = 4;
c.beginPath(); c.moveTo(sx(sm), y1); c.lineTo(sx(sm), y0); c.stroke();
// current point
const my = C.MY0 + s / 2;
c.fillStyle = '#ffffff'; c.beginPath(); c.arc(sx(Math.min(s, sMaxP)), sy(my), 8, 0, 7); c.fill();
c.strokeStyle = '#ffffff'; c.lineWidth = 3;
c.beginPath(); c.arc(sx(Math.min(s, sMaxP)), sy(my), 8, 0, 7); c.stroke();
// markers
c.fillStyle = '#37d67a'; c.textAlign = 'left';
c.fillText('latch 1.45 m', x0 + 10, sy(C.LATCH_Y) - 12);
c.fillStyle = '#ff6b5e'; c.fillText('stop limits s = ' + sm.toFixed(2) + ' m', sx(sm) + 10, y1 + 28);
}
function refreshHUD() {
const sm = sMaxNow();
const maxH = C.MY0 + sm / 2;
const reach = maxH >= C.LATCH_Y - 1e-6;
el.allowed.textContent = sm.toFixed(3) + ' m';
el.maxh.textContent = maxH.toFixed(3) + ' m';
el.short.textContent = (reach ? '— (reachable)' : (C.LATCH_Y - maxH).toFixed(3) + ' m');
el.verdict.className = 'verdict ' + (reach ? 'yes' : 'no');
el.verdict.textContent = reach
? 'PREDICTION: YES — pull of ' + REQUIRED.toFixed(2) + ' m is within the ' + sm.toFixed(2) + ' m the stop allows, so the load reaches the latch.'
: 'PREDICTION: NO — the latch needs ' + REQUIRED.toFixed(2) + ' m of pull (1.10 m = 2 × 0.55 m lift) but the hard stop allows only ' + sm.toFixed(2) + ' m ⇒ max height ' + maxH.toFixed(3) + ' m < 1.450 m.';
el.L.textContent = L0.toFixed(3);
el.s.textContent = s.toFixed(3);
el.y.textContent = (C.MY0 + s / 2).toFixed(3);
el.st.textContent = latched ? 'CLOSED ✔' : 'open';
el.st.style.color = latched ? '#7dffb0' : '#ffb3b3';
el.stopv.textContent = stopY.toFixed(2) + ' m';
drawPlot();
if (tested) {
const my = C.MY0 + s / 2;
el.actual.style.display = 'block';
el.actual.className = 'verdict ' + (latched ? 'yes' : 'no');
el.actual.textContent = latched
? 'TEST RESULT: LATCHED — load axis reached ' + my.toFixed(3) + ' m, catch closed and holds the load.'
: 'TEST RESULT: load topped out at ' + my.toFixed(3) + ' m (handle bottomed on the hard stop). Latch NOT reached — short by ' + (C.LATCH_Y - my).toFixed(3) + ' m.';
}
}
/* controls */
el.slider.addEventListener('input', e => { stopY = parseFloat(e.target.value); refreshHUD(); });
$('remove').addEventListener('click', () => { stopY = 0.0; el.slider.value = 0; refreshHUD(); });
$('reset').addEventListener('click', () => { s = 0; latched = false; tested = false; auto = false; refreshHUD(); });
const btnPull = $('pull');
btnPull.addEventListener('pointerdown', e => { auto = true; tested = true; btnPull.setPointerCapture(e.pointerId); });
['pointerup', 'pointercancel', 'pointerleave'].forEach(ev => btnPull.addEventListener(ev, () => { auto = false; }));
$('labels').addEventListener('change', e => { labelG.visible = e.target.checked; });
/* ───────────────────────── LOOP ───────────────────────── */
let ropeDirty = true, armAngle = 1.55;
const clock = new THREE.Clock();
function tick() {
requestAnimationFrame(tick);
const dt = Math.min(clock.getDelta(), 0.05);
if (auto && !latched) { s = Math.min(s + 0.42 * dt, sMaxNow()); if (s > 0) tested = true; }
const sm = sMaxNow();
if (s > sm) s = sm;
const hy = C.HY0 - s; // free rope end
const my = C.MY0 + s / 2; // ← constant rope length enforced here
if (!latched && my >= C.LATCH_Y - 1e-4) { latched = true; sLatch = s; }
if (latched) s = sLatch;
load.position.y = my;
handle.position.y = hy;
stopG.position.y = stopY;
lMov.position.y = my + 0.46;
lStop.position.y = stopY + 0.30;
lLatch.position.y = CATCH_Y + 0.32;
const target = latched ? 0.30 : 1.55;
armAngle += (target - armAngle) * Math.min(1, dt * 9);
arm.rotation.z = armAngle;
ropeDirty = true; // geometry follows the constrained state
if (ropeDirty) { buildRope(my, hy); ropeDirty = false; }
updateCam();
renderer.render(scene, camera);
refreshHUD();
}
tick();
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```