Prompt specification
Build or customize the Three.js 3D scene "Short-handle ratchet cycle" 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: Short-handle ratchet cycle
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/short-handle-ratchet-cycle-x0294
Scene Description Prompt:
Animate a low-poly ratchet handle rocking while its pawl advances the wheel one way. Three.js from cdnjs, one HTML file.
Working Three.js Starter (short-handle-ratchet-cycle-x0294):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Low-Poly Ratchet Mechanism</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
color: #eaf6ff;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
}
.title {
position: absolute;
top: 24px;
left: 28px;
}
.eyebrow {
margin-bottom: 7px;
color: #63e6d8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 38px);
font-weight: 760;
letter-spacing: -0.04em;
}
.subtitle {
margin-top: 7px;
color: #91a7ba;
font-size: 13px;
}
.status {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 11px 15px;
border: 1px solid rgba(117, 231, 218, 0.18);
border-radius: 999px;
background: rgba(8, 21, 35, 0.72);
backdrop-filter: blur(12px);
color: #a9bdd0;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #65778a;
box-shadow: 0 0 0 4px rgba(101, 119, 138, 0.12);
transition: background 120ms, box-shadow 120ms;
}
.status.active .status-dot {
background: #63e6d8;
box-shadow: 0 0 0 4px rgba(99, 230, 216, 0.14),
0 0 16px rgba(99, 230, 216, 0.7);
}
.status.active {
color: #dffffb;
border-color: rgba(99, 230, 216, 0.35);
}
.help {
position: absolute;
left: 28px;
bottom: 27px;
color: #6f879d;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 600px) {
.title {
top: 18px;
left: 18px;
}
.subtitle {
max-width: 240px;
}
.help {
left: 18px;
bottom: 19px;
}
.status {
right: 16px;
bottom: 16px;
max-width: 60vw;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="title">
<div class="eyebrow">Mechanical Study / 01</div>
<h1>One-Way Ratchet</h1>
<div class="subtitle">The handle rocks while the pawl carries the wheel forward.</div>
</div>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="status" id="status">
<span class="status-dot"></span>
<span id="statusText">Free stroke</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 12, 26);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.65, 0.25, 0);
let cameraYaw = 0.48;
let cameraPitch = 0.25;
let cameraRadius = 9.5;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbfe8ff, 0x152234, 2.0));
const keyLight = new THREE.DirectionalLight(0xffe0b2, 3.4);
keyLight.position.set(4.5, 7, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x36dfd0, 28, 18, 2);
rimLight.position.set(-4, 2.8, 4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff784e, 20, 13, 2);
warmLight.position.set(4.5, -0.5, 3);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const material = {
gold: new THREE.MeshStandardMaterial({
color: 0xe4a52b,
roughness: 0.42,
metalness: 0.72,
flatShading: true
}),
goldDark: new THREE.MeshStandardMaterial({
color: 0xa96317,
roughness: 0.48,
metalness: 0.75,
flatShading: true
}),
goldLight: new THREE.MeshStandardMaterial({
color: 0xf4c65d,
roughness: 0.38,
metalness: 0.66,
flatShading: true
}),
steel: new THREE.MeshStandardMaterial({
color: 0xc3ced7,
roughness: 0.28,
metalness: 0.86,
flatShading: true
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x233347,
roughness: 0.48,
metalness: 0.72,
flatShading: true
}),
darkerSteel: new THREE.MeshStandardMaterial({
color: 0x101c2c,
roughness: 0.55,
metalness: 0.65,
flatShading: true
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x0a776f,
roughness: 0.78,
metalness: 0.08,
flatShading: true
}),
rubberBand: new THREE.MeshStandardMaterial({
color: 0x5ce0d1,
roughness: 0.55,
metalness: 0.12,
flatShading: true
}),
coral: new THREE.MeshStandardMaterial({
color: 0xff6848,
roughness: 0.4,
metalness: 0.25,
emissive: 0x351008,
emissiveIntensity: 0.35,
flatShading: true
}),
cyan: new THREE.MeshBasicMaterial({
color: 0x63e6d8
})
};
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
function box(width, height, depth, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(radius, depth, mat, x, y, z, segments = 16, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, depth, segments),
mat
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function smoothstep(edge0, edge1, value) {
const x = THREE.MathUtils.clamp(
(value - edge0) / (edge1 - edge0),
0,
1
);
return x * x * (3 - 2 * x);
}
// -------------------------------------------------------------------------
// Ground, base, and rear frame
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x0a1726,
roughness: 0.94,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.69;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x27435a, 0x15283a);
grid.position.y = -1.675;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
box(6.5, 0.24, 2.25, material.darkerSteel, 0.75, -1.53, -0.18);
box(6.15, 0.06, 1.92, material.darkSteel, 0.75, -1.38, -0.18);
// Rear wheel support and pawl mounting bracket.
box(0.28, 2.0, 0.32, material.darkSteel, -1.58, -0.38, -0.55);
box(1.65, 0.25, 0.32, material.darkSteel, -0.78, 0, -0.55);
box(0.2, 2.62, 0.28, material.darkSteel, 0.69, 0.78, -0.56);
box(0.88, 0.2, 0.28, material.darkSteel, 0.26, 2.29, -0.56);
// Base fasteners.
for (const x of [-2.1, 3.65]) {
for (const z of [-0.9, 0.55]) {
cylinder(0.09, 0.08, material.steel, x, -1.34, z, 8);
}
}
// -------------------------------------------------------------------------
// Ratchet wheel
// -------------------------------------------------------------------------
const wheel = new THREE.Group();
scene.add(wheel);
// Main wheel body.
cylinder(1.06, 0.44, material.goldDark, 0, 0, 0, 32, wheel);
// Front face.
cylinder(0.87, 0.48, material.gold, 0, 0, 0.035, 32, wheel);
// Faceted outer ring.
const outerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.92, 0.055, 6, 32),
material.goldLight
);
outerRing.position.z = 0.29;
outerRing.castShadow = true;
wheel.add(outerRing);
// Shared asymmetric tooth geometry.
const toothShape = new THREE.Shape();
toothShape.moveTo(-0.145, 1.015);
toothShape.lineTo(0.145, 1.015);
toothShape.lineTo(0.145, 1.355);
toothShape.lineTo(-0.075, 1.355);
toothShape.closePath();
const toothGeometry = new THREE.ExtrudeGeometry(toothShape, {
depth: 0.23,
bevelEnabled: false,
curveSegments: 1
});
toothGeometry.translate(0, 0, -0.115);
const TOOTH_COUNT = 18;
const TOOTH_STEP = Math.PI * 2 / TOOTH_COUNT;
for (let i = 0; i < TOOTH_COUNT; i++) {
const angle = i * TOOTH_STEP;
const tooth = new THREE.Mesh(toothGeometry, material.goldLight);
tooth.rotation.z = angle - Math.PI / 2;
tooth.castShadow = true;
tooth.receiveShadow = true;
wheel.add(tooth);
}
// Bolts around the face.
for (let i = 0; i < 6; i++) {
const a = i * Math.PI / 3;
const bolt = cylinder(
0.075,
0.075,
material.darkerSteel,
Math.cos(a) * 0.61,
Math.sin(a) * 0.61,
0.31,
6,
wheel
);
bolt.castShadow = true;
}
// Asymmetric index mark makes the wheel's rotation easy to see.
const indexMark = box(
0.25,
0.085,
0.065,
material.coral,
0.73,
0,
0.315,
wheel
);
indexMark.rotation.z = -0.15;
// Hub and cap.
cylinder(0.35, 0.7, material.darkSteel, 0, 0, 0.06, 16, wheel);
cylinder(0.26, 0.12, material.steel, 0, 0, 0.45, 12, wheel);
cylinder(0.085, 0.15, material.coral, 0, 0, 0.51, 8, wheel);
// Fixed axle behind the rotating wheel.
cylinder(0.13, 1.55, material.steel, 0, 0, -0.12, 12);
// -------------------------------------------------------------------------
// Pawl
// -------------------------------------------------------------------------
const pawl = new THREE.Group();
pawl.position.set(0, 2.31, 0.48);
scene.add(pawl);
const pawlShape = new THREE.Shape();
pawlShape.moveTo(-0.17, 0.18);
pawlShape.lineTo(0.17, 0.18);
pawlShape.lineTo(0.13, -0.62);
pawlShape.lineTo(0.26, -0.83);
pawlShape.lineTo(0, -1.03);
pawlShape.lineTo(-0.13, -0.82);
pawlShape.closePath();
const pawlGeometry = new THREE.ExtrudeGeometry(pawlShape, {
depth: 0.18,
bevelEnabled: false,
curveSegments: 1
});
pawlGeometry.translate(0, 0, -0.09);
const pawlBody = new THREE.Mesh(pawlGeometry, material.steel);
pawlBody.castShadow = true;
pawlBody.receiveShadow = true;
pawl.add(pawlBody);
// Colored pawl tooth.
const pawlTip = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.27, 3),
material.coral
);
pawlTip.rotation.z = Math.PI;
pawlTip.position.set(0, -0.98, 0.005);
pawlTip.castShadow = true;
pawl.add(pawlTip);
// Pivot pin remains visually fixed while the pawl rocks around it.
cylinder(0.18, 0.26, material.darkSteel, 0, 2.31, 0.5, 12);
cylinder(0.075, 0.29, material.coral, 0, 2.31, 0.53, 8);
// Small return spring, made from simple faceted segments.
box(0.07, 0.42, 0.08, material.rubberBand, -0.23, 2.12, 0.34);
// -------------------------------------------------------------------------
// Rocking handle
// -------------------------------------------------------------------------
const handle = new THREE.Group();
handle.position.set(0, 0, 0.59);
scene.add(handle);
box(2.9, 0.25, 0.27, material.darkSteel, 2.0, 0, 0, handle);
// Narrow highlight strip gives the handle a low-poly industrial silhouette.
box(
2.55,
0.035,
0.285,
material.rubberBand,
2.02,
0.095,
0,
handle
);
const handleCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.23, 0.48, 10),
material.coral
);
handleCollar.rotation.z = -Math.PI / 2;
handleCollar.position.x = 0.72;
handleCollar.castShadow = true;
handle.add(handleCollar);
const grip = new THREE.Mesh(
new THREE.CylinderGeometry(0.255, 0.255, 1.26, 8),
material.rubber
);
grip.rotation.z = -Math.PI / 2;
grip.position.x = 3.31;
grip.castShadow = true;
handle.add(grip);
for (const x of [2.82, 3.07, 3.32, 3.57]) {
const band = new THREE.Mesh(
new THREE.TorusGeometry(0.258, 0.024, 5, 12),
material.rubberBand
);
band.rotation.y = Math.PI / 2;
band.position.x = x;
band.castShadow = true;
handle.add(band);
}
const gripEnd = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.08, 8),
material.coral
);
gripEnd.rotation.z = -Math.PI / 2;
gripEnd.position.x = 3.96;
gripEnd.castShadow = true;
handle.add(gripEnd);
// -------------------------------------------------------------------------
// One-way direction arrow
// -------------------------------------------------------------------------
const arrow = new THREE.Group();
arrow.position.z = 0.53;
scene.add(arrow);
const arrowArc = new THREE.Mesh(
new THREE.TorusGeometry(1.68, 0.025, 5, 56, Math.PI * 1.42),
material.cyan
);
arrow.add(arrowArc);
const arrowAngle = Math.PI * 1.42;
const tangent = new THREE.Vector3(
-Math.sin(arrowAngle),
Math.cos(arrowAngle),
0
);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.29, 6),
material.cyan
);
arrowHead.position.set(
Math.cos(arrowAngle) * 1.68 + tangent.x * 0.08,
Math.sin(arrowAngle) * 1.68 + tangent.y * 0.08,
0
);
arrowHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrow.add(arrowHead);
// Procedural 3D label.
function createLabel(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 24, 38, 0.84)";
context.strokeStyle = "rgba(99, 230, 216, 0.65)";
context.lineWidth = 5;
context.beginPath();
context.roundRect(4, 4, 504, 120, 28);
context.fill();
context.stroke();
context.fillStyle = "#8ff7eb";
context.font = "800 54px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
sprite.scale.set(1.65, 0.41, 1);
return sprite;
}
const label = createLabel("ONE WAY");
label.position.set(1.72, -1.08, 0.85);
scene.add(label);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const CYCLE_DURATION = 1.6;
const INITIAL_WHEEL_ANGLE = TOOTH_STEP * 0.5;
const status = document.getElementById("status");
const statusText = document.getElementById("statusText");
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const cycle = Math.floor(elapsed / CYCLE_DURATION);
const phase = (elapsed % CYCLE_DURATION) / CYCLE_DURATION;
// The handle rocks continuously between approximately -25° and +30°.
const handleAngle = 0.05 + 0.48 * Math.cos(phase * Math.PI * 2);
handle.rotation.z = handleAngle;
// The pawl lifts over a tooth, then the wheel advances exactly one tooth.
// Positive Z rotation is counter-clockwise when viewed from the front.
const wheelAdvance = smoothstep(0.50, 0.72, phase);
wheel.rotation.z =
INITIAL_WHEEL_ANGLE + (cycle + wheelAdvance) * TOOTH_STEP;
// Pawl deflection and visible click/reset motion.
const pawlLift =
smoothstep(0.45, 0.52, phase) *
(1 - smoothstep(0.68, 0.76, phase));
pawl.rotation.z = -0.025 + pawlLift * 0.25;
pawl.position.y = 2.31 + pawlLift * 0.025;
// Subtle indicator pulse while the drive is active.
const pulse = 1 + pawlLift * 0.25;
indexMark.scale.y = pulse;
if (pawlLift > 0.16) {
status.classList.add("active");
statusText.textContent = "Pawl engaged · wheel advancing";
} else if (phase < 0.45) {
status.classList.remove("active");
statusText.textContent = "Free stroke";
} else {
status.classList.remove("active");
statusText.textContent = "Pawl reset · ready";
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// -------------------------------------------------------------------------
// Direct camera controls: no addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.0045,
-0.12,
0.85
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.007,
6.2,
15
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraYaw = 0.48;
cameraPitch = 0.25;
cameraRadius = 9.5;
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
});
</script>
</body>
</html>
```