Prompt specification
Build or customize the Three.js 3D scene "Rope Around One Fixed Pulley" 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: Rope Around One Fixed Pulley
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rope-around-one-fixed-pulley-x3493
Scene Description Prompt:
Model a rope bending around a fixed pulley with two straight hanging segments. Keep tangency and attachment points consistent as one end is moved. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (rope-around-one-fixed-pulley-x3493):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fixed Pulley with Constant-Length Rope</title>
<style>
:root {
color-scheme: light;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eef1;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
top: 18px;
left: 18px;
width: min(320px, calc(100vw - 36px));
padding: 16px 18px;
border: 1px solid rgba(30, 48, 60, 0.14);
border-radius: 14px;
background: rgba(249, 252, 253, 0.88);
box-shadow: 0 12px 35px rgba(29, 50, 64, 0.12);
backdrop-filter: blur(10px);
pointer-events: none;
user-select: none;
}
h1 {
margin: 0 0 6px;
font-size: 18px;
letter-spacing: -0.02em;
}
.subtitle {
margin: 0 0 13px;
color: #536572;
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
gap: 16px;
margin-bottom: 13px;
color: #334652;
font-size: 12px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
}
.dot.left {
background: #08b8d4;
}
.dot.right {
background: #ec4899;
}
.readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
padding: 9px 10px;
border-radius: 9px;
background: rgba(38, 62, 76, 0.06);
}
.metric small {
display: block;
margin-bottom: 2px;
color: #657582;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
font-size: 14px;
}
.total {
margin-top: 10px;
color: #536572;
font-size: 12px;
text-align: right;
}
.controls {
position: fixed;
bottom: 18px;
left: 50%;
display: flex;
align-items: center;
gap: 14px;
width: min(520px, calc(100vw - 36px));
padding: 12px 14px;
transform: translateX(-50%);
border: 1px solid rgba(30, 48, 60, 0.14);
border-radius: 14px;
background: rgba(249, 252, 253, 0.9);
box-shadow: 0 12px 35px rgba(29, 50, 64, 0.12);
backdrop-filter: blur(10px);
}
.slider-label {
flex: 1;
min-width: 0;
font-size: 12px;
font-weight: 650;
color: #334652;
}
input[type="range"] {
display: block;
width: 100%;
margin-top: 7px;
accent-color: #08a9c4;
cursor: pointer;
}
button {
padding: 9px 12px;
border: 1px solid #c9d5db;
border-radius: 9px;
background: #ffffff;
color: #334652;
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
}
button:hover {
border-color: #9eb1bc;
background: #f4f8fa;
}
.hint {
position: fixed;
right: 18px;
bottom: 20px;
color: #536572;
font-size: 12px;
pointer-events: none;
user-select: none;
}
@media (max-width: 700px) {
.panel {
padding: 12px 14px;
}
.subtitle {
display: none;
}
.legend {
margin-bottom: 9px;
}
.hint {
display: none;
}
.controls {
gap: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<section class="panel">
<h1>Fixed Pulley</h1>
<p class="subtitle">
Constant-length rope with mathematically fixed tangency points.
Move one hanging end and the opposite attachment compensates.
</p>
<div class="legend">
<span><i class="dot left"></i>Left attachment</span>
<span><i class="dot right"></i>Right attachment</span>
</div>
<div class="readout">
<div class="metric">
<small>Left length</small>
<strong id="leftMetric">2.20 m</strong>
</div>
<div class="metric">
<small>Right length</small>
<strong id="rightMetric">2.20 m</strong>
</div>
</div>
<div class="total">
Total rope length: <strong id="totalMetric">7.70 m</strong>
</div>
</section>
<div class="controls">
<label class="slider-label" for="lengthSlider">
Left hanging length
<input
id="lengthSlider"
type="range"
min="1.5"
max="2.9"
step="0.001"
value="2.2"
>
</label>
<button id="resetButton" type="button">Reset</button>
</div>
<div class="hint">Drag either colored attachment vertically</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 renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eef1);
const camera = new THREE.OrthographicCamera(-5, 5, 3.2, -3.2, 0.1, 100);
camera.position.set(0, 2.25, 10);
camera.lookAt(0, 2.25, 0);
const hemisphere = new THREE.HemisphereLight(
0xf4fbff,
0x71808a,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.0);
keyLight.position.set(-4, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dcff, 1.1);
fillLight.position.set(5, 4, 2);
scene.add(fillLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xd7e2e6,
roughness: 0.95,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = 0;
ground.receiveShadow = true;
scene.add(ground);
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x71838e,
roughness: 0.72,
metalness: 0.22,
flatShading: true
});
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x304b5b,
roughness: 0.58,
metalness: 0.38,
flatShading: true
});
const spokeMaterial = new THREE.MeshStandardMaterial({
color: 0x648594,
roughness: 0.68,
metalness: 0.25,
flatShading: true
});
const hubMaterial = new THREE.MeshStandardMaterial({
color: 0xe9ad45,
roughness: 0.52,
metalness: 0.35,
flatShading: true
});
const ropeMaterial = new THREE.MeshStandardMaterial({
color: 0xf29a32,
roughness: 0.8,
metalness: 0.02,
flatShading: true
});
const leftMaterial = new THREE.MeshStandardMaterial({
color: 0x08b8d4,
roughness: 0.42,
metalness: 0.2,
flatShading: true
});
const rightMaterial = new THREE.MeshStandardMaterial({
color: 0xec4899,
roughness: 0.42,
metalness: 0.2,
flatShading: true
});
const PULLEY_Y = 3.5;
const PULLEY_RADIUS = 1.05;
const ROPE_RADIUS = 0.047;
const VERTICAL_ROPE_LENGTH = 4.4;
const INITIAL_LEFT_LENGTH = 2.2;
const MAX_HANGING_LENGTH = 2.9;
// Both ends remain above the floor.
const MIN_HANGING_LENGTH =
VERTICAL_ROPE_LENGTH - MAX_HANGING_LENGTH;
const TOTAL_ROPE_LENGTH =
VERTICAL_ROPE_LENGTH + Math.PI * PULLEY_RADIUS;
function cylinderBetween(a, b, radius, material, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// Fixed support frame behind the pulley.
const support = new THREE.Group();
scene.add(support);
const base = new THREE.Mesh(
new THREE.BoxGeometry(2.25, 0.18, 0.9),
supportMaterial
);
base.position.set(0, 0.09, -0.43);
base.castShadow = true;
base.receiveShadow = true;
support.add(base);
support.add(
cylinderBetween(
new THREE.Vector3(-0.82, 0.18, -0.43),
new THREE.Vector3(0, PULLEY_Y, -0.43),
0.09,
supportMaterial
)
);
support.add(
cylinderBetween(
new THREE.Vector3(0.82, 0.18, -0.43),
new THREE.Vector3(0, PULLEY_Y, -0.43),
0.09,
supportMaterial
)
);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.15, 0.9, 12),
supportMaterial
);
axle.rotation.x = Math.PI / 2;
axle.position.set(0, PULLEY_Y, -0.05);
axle.castShadow = true;
support.add(axle);
const axleCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.21, 0.21, 0.09, 12),
hubMaterial
);
axleCap.rotation.x = Math.PI / 2;
axleCap.position.set(0, PULLEY_Y, 0.42);
axleCap.castShadow = true;
support.add(axleCap);
// Rotating pulley wheel; its center remains fixed.
const wheel = new THREE.Group();
wheel.position.set(0, PULLEY_Y, 0);
scene.add(wheel);
const outerRim = new THREE.Mesh(
new THREE.TorusGeometry(
PULLEY_RADIUS - 0.13,
0.08,
8,
24
),
rimMaterial
);
outerRim.castShadow = true;
outerRim.receiveShadow = true;
wheel.add(outerRim);
const innerRim = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.035, 6, 16),
rimMaterial
);
innerRim.castShadow = true;
wheel.add(innerRim);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.22, 0.32, 12),
hubMaterial
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
wheel.add(hub);
const spokeGeometry = new THREE.BoxGeometry(0.13, 0.72, 0.12);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const spoke = new THREE.Mesh(spokeGeometry, spokeMaterial);
spoke.position.set(
Math.cos(angle) * 0.52,
Math.sin(angle) * 0.52,
0
);
// Local +Y is aligned with the radial direction.
spoke.rotation.z = angle - Math.PI / 2;
spoke.castShadow = true;
spoke.receiveShadow = true;
wheel.add(spoke);
}
/*
The rope contacts the upper semicircle of the pulley.
Its centerline is:
x = R cos(theta)
y = PULLEY_Y + R sin(theta)
theta runs from PI to 0. Therefore the two tangent points are
exactly (-R, PULLEY_Y) and (R, PULLEY_Y), matching the
vertical hanging segments.
*/
class PulleyArcCurve extends THREE.Curve {
getPoint(t, target = new THREE.Vector3()) {
const theta = Math.PI * (1 - t);
return target.set(
Math.cos(theta) * PULLEY_RADIUS,
PULLEY_Y + Math.sin(theta) * PULLEY_RADIUS,
0
);
}
}
const contactArc = new THREE.Mesh(
new THREE.TubeGeometry(
new PulleyArcCurve(),
32,
ROPE_RADIUS,
6,
false
),
ropeMaterial
);
contactArc.castShadow = true;
contactArc.receiveShadow = true;
scene.add(contactArc);
// Rounded caps hide the joins at the two exact tangent points.
const tangentGeometry = new THREE.SphereGeometry(
ROPE_RADIUS * 1.03,
8,
6
);
for (const x of [-PULLEY_RADIUS, PULLEY_RADIUS]) {
const tangentJoint = new THREE.Mesh(
tangentGeometry,
ropeMaterial
);
tangentJoint.position.set(x, PULLEY_Y, 0);
tangentJoint.castShadow = true;
scene.add(tangentJoint);
}
// Unit-height cylinders are scaled to the current hanging lengths.
const straightRopeGeometry = new THREE.CylinderGeometry(
ROPE_RADIUS,
ROPE_RADIUS,
1,
8,
1,
false
);
const leftRope = new THREE.Mesh(
straightRopeGeometry,
ropeMaterial
);
leftRope.castShadow = true;
leftRope.receiveShadow = true;
scene.add(leftRope);
const rightRope = new THREE.Mesh(
straightRopeGeometry,
ropeMaterial
);
rightRope.castShadow = true;
rightRope.receiveShadow = true;
scene.add(rightRope);
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const handleHitMeshes = [];
function createAttachment(side, material) {
const group = new THREE.Group();
// The ring center is the actual rope attachment point.
const eye = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.028, 6, 12),
material
);
eye.castShadow = true;
group.add(eye);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.18, 6),
material
);
stem.position.y = -0.14;
stem.castShadow = true;
group.add(stem);
const weight = new THREE.Mesh(
new THREE.BoxGeometry(0.26, 0.22, 0.2),
material
);
weight.position.y = -0.31;
weight.castShadow = true;
weight.receiveShadow = true;
group.add(weight);
const inset = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.015),
rimMaterial
);
inset.position.set(0, -0.31, 0.107);
group.add(inset);
// Larger invisible hit volume for easy dragging.
const hitMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.3, 8, 6),
hitMaterial
);
hitMesh.position.y = -0.05;
hitMesh.userData.side = side;
group.add(hitMesh);
handleHitMeshes.push(hitMesh);
scene.add(group);
return group;
}
const leftAttachment = createAttachment("left", leftMaterial);
const rightAttachment = createAttachment("right", rightMaterial);
const slider = document.querySelector("#lengthSlider");
const leftMetric = document.querySelector("#leftMetric");
const rightMetric = document.querySelector("#rightMetric");
const totalMetric = document.querySelector("#totalMetric");
slider.min = MIN_HANGING_LENGTH;
slider.max = MAX_HANGING_LENGTH;
totalMetric.textContent = `${TOTAL_ROPE_LENGTH.toFixed(2)} m`;
let leftLength = INITIAL_LEFT_LENGTH;
let rightLength = VERTICAL_ROPE_LENGTH - INITIAL_LEFT_LENGTH;
function updateModel() {
const leftEndY = PULLEY_Y - leftLength;
const rightEndY = PULLEY_Y - rightLength;
// Straight vertical segments terminate at the tangent heights.
leftRope.position.set(
-PULLEY_RADIUS,
(PULLEY_Y + leftEndY) * 0.5,
0
);
leftRope.scale.y = leftLength;
rightRope.position.set(
PULLEY_RADIUS,
(PULLEY_Y + rightEndY) * 0.5,
0
);
rightRope.scale.y = rightLength;
// Attachment origins are always exactly at the rope endpoints.
leftAttachment.position.set(
-PULLEY_RADIUS,
leftEndY,
0
);
rightAttachment.position.set(
PULLEY_RADIUS,
rightEndY,
0
);
// The wheel can rotate, but its center remains fixed.
wheel.rotation.z =
(leftLength - INITIAL_LEFT_LENGTH) / PULLEY_RADIUS;
slider.value = leftLength.toFixed(3);
leftMetric.textContent = `${leftLength.toFixed(2)} m`;
rightMetric.textContent = `${rightLength.toFixed(2)} m`;
}
function setLeftLength(value) {
const clamped = THREE.MathUtils.clamp(
value,
MIN_HANGING_LENGTH,
MAX_HANGING_LENGTH
);
leftLength = clamped;
rightLength = VERTICAL_ROPE_LENGTH - leftLength;
updateModel();
}
function setRightLength(value) {
const clamped = THREE.MathUtils.clamp(
value,
MIN_HANGING_LENGTH,
MAX_HANGING_LENGTH
);
rightLength = clamped;
leftLength = VERTICAL_ROPE_LENGTH - rightLength;
updateModel();
}
updateModel();
slider.addEventListener("input", () => {
setLeftLength(Number(slider.value));
});
document.querySelector("#resetButton").addEventListener("click", () => {
setLeftLength(INITIAL_LEFT_LENGTH);
});
// Direct pointer interaction; no external camera-control addons.
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 0, 1),
0
);
const dragPoint = new THREE.Vector3();
let draggedSide = null;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function getHandleUnderPointer() {
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
handleHitMeshes,
false
);
return intersections.length > 0
? intersections[0].object.userData.side
: null;
}
function dragToPointer(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
if (!raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
return;
}
// Convert world Y to the requested hanging length.
const requestedLength = PULLEY_Y - dragPoint.y;
if (draggedSide === "left") {
setLeftLength(requestedLength);
} else if (draggedSide === "right") {
setRightLength(requestedLength);
}
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) {
return;
}
updatePointer(event);
const side = getHandleUnderPointer();
if (!side) {
return;
}
draggedSide = side;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
dragToPointer(event);
event.preventDefault();
});
canvas.addEventListener("pointermove", (event) => {
updatePointer(event);
if (draggedSide) {
dragToPointer(event);
} else {
canvas.style.cursor =
getHandleUnderPointer() ? "grab" : "default";
}
});
function endDrag(event) {
if (!draggedSide) {
return;
}
draggedSide = null;
canvas.style.cursor = "default";
if (
event.pointerType !== "mouse" &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = 6.4;
camera.left = -viewHeight * aspect * 0.5;
camera.right = viewHeight * aspect * 0.5;
camera.top = viewHeight * 0.5;
camera.bottom = -viewHeight * 0.5;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```