Prompt specification
Build or customize the Three.js 3D scene "Pulley Ratio With Belt Markers" 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 Ratio With Belt Markers
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pulley-ratio-with-belt-markers-x2010
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: pulley ratio with belt markers. Animate a belt drive with visible markers moving at one linear speed. Couple pulley angular speeds to radii under an explicit no-slip assumption.
Working Three.js Starter (pulley-ratio-with-belt-markers-x2010):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Open-Belt Drive</title>
<style>
:root {
--ink: #14242c;
--muted: #60727a;
--panel: rgba(248, 252, 253, 0.88);
--border: rgba(20, 36, 44, 0.13);
--accent: #f4b942;
--driver: #229c98;
--driven: #ed815b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7eb;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dce7eb;
color: #39515b;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 220ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
#ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel {
position: absolute;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(31, 54, 63, 0.13),
inset 0 1px 0 rgba(255, 255, 255, 0.85);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(380px, calc(100vw - 44px));
padding: 18px 20px 17px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #527078;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 0 3px rgba(244, 185, 66, 0.18);
content: "";
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.stats {
left: 22px;
bottom: 22px;
width: min(520px, calc(100vw - 44px));
padding: 15px;
}
.stat-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 9px;
}
.stat {
min-width: 0;
padding: 11px 12px;
border: 1px solid rgba(20, 36, 44, 0.09);
border-radius: 11px;
background: rgba(255, 255, 255, 0.55);
}
.stat-label {
display: block;
margin-bottom: 6px;
overflow: hidden;
color: #72858c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.stat-value {
display: block;
color: #1e333c;
font-size: 17px;
font-variant-numeric: tabular-nums;
font-weight: 800;
letter-spacing: -0.035em;
white-space: nowrap;
}
.stat-value small {
color: #73858b;
font-size: 10px;
font-weight: 700;
letter-spacing: 0;
}
.equation {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 8px 16px;
margin-top: 11px;
padding: 10px 12px;
border-radius: 10px;
background: #20343d;
color: #eef8fa;
font-size: 12px;
}
.equation strong {
color: var(--accent);
font-weight: 800;
}
.no-slip {
color: #b9d8d5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
.controls {
top: 22px;
right: 22px;
width: 275px;
padding: 15px;
pointer-events: auto;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
button {
min-width: 78px;
padding: 9px 13px;
border: 0;
border-radius: 9px;
background: #20343d;
color: white;
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 800;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
background: #2c4954;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.speed-label {
display: flex;
justify-content: space-between;
margin: 15px 0 8px;
color: #61747c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
output {
color: #243943;
font-variant-numeric: tabular-nums;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: #d89c20;
cursor: pointer;
}
.hint {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(20, 36, 44, 0.1);
color: #71838a;
font-size: 10px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 14px;
margin-top: 9px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
color: #536970;
font-size: 10px;
font-weight: 700;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
@media (max-width: 720px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
.controls {
top: 108px;
right: 12px;
width: 225px;
padding: 12px;
}
.stats {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 10px;
}
.stat-grid {
grid-template-columns: repeat(2, 1fr);
}
.stat {
padding: 8px 10px;
}
.equation {
align-items: flex-start;
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="loading">Building voxel belt drive…</div>
<div id="ui">
<section class="panel title-panel">
<div class="eyebrow">No-slip belt transmission</div>
<h1>Open Belt Drive</h1>
<p class="subtitle">
One rigid belt, two pitch radii, and one shared linear speed.
Every yellow marker advances by the same arc-length distance.
</p>
</section>
<section class="panel stats">
<div class="stat-grid">
<div class="stat">
<span class="stat-label">Belt speed</span>
<span class="stat-value"><span id="beltSpeed">2.40</span> <small>m/s</small></span>
</div>
<div class="stat">
<span class="stat-label">Driver</span>
<span class="stat-value"><span id="driverOmega">1.66</span> <small>rad/s</small></span>
</div>
<div class="stat">
<span class="stat-label">Driven</span>
<span class="stat-value"><span id="drivenOmega">2.67</span> <small>rad/s</small></span>
</div>
<div class="stat">
<span class="stat-label">Speed ratio</span>
<span class="stat-value" id="ratioValue">1.61:1</span>
</div>
</div>
<div class="equation">
<span><strong>v = ω₁R₁ = ω₂R₂</strong> · ω₂/ω₁ = R₁/R₂</span>
<span class="no-slip">Explicit no-slip assumption</span>
</div>
</section>
<section class="panel controls">
<div class="control-row">
<button id="playButton" type="button">Pause</button>
<div class="legend">
<span><i class="swatch" style="background:#229c98"></i>Driver</span>
<span><i class="swatch" style="background:#ed815b"></i>Driven</span>
<span><i class="swatch" style="background:#f4b942"></i>Marker</span>
</div>
</div>
<label class="speed-label" for="speedInput">
Belt linear speed
<output id="speedOutput" for="speedInput">2.40 m/s</output>
</label>
<input
id="speedInput"
type="range"
min="0.5"
max="4"
step="0.05"
value="2.4"
>
<div class="hint">
Drag to orbit · wheel to zoom · Shift-drag to pan ·
double-click to reset the camera.
</div>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7eb);
scene.fog = new THREE.Fog(0xdce7eb, 15, 29);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xffffff, 0x63737a, 2.1);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff7e9, 3.2);
key.position.set(3.5, 8, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.00015;
scene.add(key);
const rimLight = new THREE.DirectionalLight(0xb9e9ff, 1.35);
rimLight.position.set(-6, 3, -5);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Shared materials and voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const materials = {
belt: new THREE.MeshStandardMaterial({
color: 0x26343b,
roughness: 0.86,
metalness: 0.06
}),
beltAlt: new THREE.MeshStandardMaterial({
color: 0x34434a,
roughness: 0.84,
metalness: 0.06
}),
steel: new THREE.MeshStandardMaterial({
color: 0x4b6069,
roughness: 0.64,
metalness: 0.35
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x263840,
roughness: 0.58,
metalness: 0.48
}),
marker: new THREE.MeshStandardMaterial({
color: 0xffca45,
emissive: 0x8a4d00,
emissiveIntensity: 0.32,
roughness: 0.48,
metalness: 0.08
}),
markerStripe: new THREE.MeshStandardMaterial({
color: 0xfff3c2,
emissive: 0xffc84f,
emissiveIntensity: 0.18,
roughness: 0.5
}),
base: new THREE.MeshStandardMaterial({
color: 0x9caeb5,
roughness: 0.92
})
};
function makeBox(parent, material, position, scale, rotationZ = 0) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(position.x, position.y, position.z);
mesh.scale.set(scale.x, scale.y, scale.z);
mesh.rotation.z = rotationZ;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeBeam(parent, material, x1, y1, x2, y2, z, width, depth) {
const dx = x2 - x1;
const dy = y2 - y1;
const length = Math.hypot(dx, dy);
return makeBox(
parent,
material,
{
x: (x1 + x2) * 0.5,
y: (y1 + y2) * 0.5,
z
},
{ x: length, y: width, z: depth },
Math.atan2(dy, dx)
);
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function makeLabelSprite(title, subtitle) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 170;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 624, 154, 24);
ctx.fillStyle = "rgba(25, 43, 51, 0.90)";
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.16)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#ffffff";
ctx.font = "800 39px system-ui, sans-serif";
ctx.fillText(title, 320, 62);
ctx.fillStyle = "#f4c85d";
ctx.font = "750 29px system-ui, sans-serif";
ctx.fillText(subtitle, 320, 112);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.15, 0.8375, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Pitch radii and exact open-belt path
//
// The pulley centers lie on X and the pulley axes lie on Z.
// The belt path consists of two straight external tangents and two arcs.
// -------------------------------------------------------------------------
const R_DRIVER = 1.45;
const R_DRIVEN = 0.90;
const C_DRIVER = new THREE.Vector2(-2.30, 0.45);
const C_DRIVEN = new THREE.Vector2(2.30, 0.45);
const FLOOR_Y = -1.55;
function createOpenBeltPath(c1, c2, r1, r2) {
const delta = c2.clone().sub(c1);
const distance = delta.length();
const dx = delta.x / distance;
const dy = delta.y / distance;
// External tangent normal. For horizontal centers this gives:
// normal.x = (r1 - r2) / centerDistance.
const nx = dx * (r1 - r2) / distance;
const ny = Math.sqrt(Math.max(0, 1 - nx * nx));
const beta = Math.acos(nx);
const upperNormal = new THREE.Vector2(nx, ny);
const lowerNormal = new THREE.Vector2(nx, -ny);
const q1Upper = c1.clone().addScaledVector(upperNormal, r1);
const q2Upper = c2.clone().addScaledVector(upperNormal, r2);
const q2Lower = c2.clone().addScaledVector(lowerNormal, r2);
const q1Lower = c1.clone().addScaledVector(lowerNormal, r1);
const segments = [];
let cursor = 0;
function addLine(a, b) {
const length = a.distanceTo(b);
segments.push({
type: "line",
start: cursor,
length,
a,
b
});
cursor += length;
}
function addArc(center, radius, startAngle, deltaAngle) {
const length = Math.abs(deltaAngle) * radius;
segments.push({
type: "arc",
start: cursor,
length,
center,
radius,
startAngle,
deltaAngle
});
cursor += length;
}
addLine(q1Upper, q2Upper);
// Small pulley: clockwise around the right side.
addArc(c2, r2, beta, -2 * beta);
addLine(q2Lower, q1Lower);
// Large pulley: clockwise around the left side.
addArc(c1, r1, -beta, beta - Math.PI * 2);
return {
length: cursor,
segments
};
}
const beltPath = createOpenBeltPath(
C_DRIVER,
C_DRIVEN,
R_DRIVER,
R_DRIVEN
);
function sampleBeltPath(distance) {
const s = ((distance % beltPath.length) + beltPath.length) % beltPath.length;
let segment = beltPath.segments[0];
for (const candidate of beltPath.segments) {
if (s <= candidate.start + candidate.length) {
segment = candidate;
break;
}
}
const local = THREE.MathUtils.clamp(
(s - segment.start) / segment.length,
0,
1
);
let point;
let tangent;
if (segment.type === "line") {
point = segment.a.clone().lerp(segment.b, local);
tangent = segment.b.clone().sub(segment.a).normalize();
} else {
const angle =
segment.startAngle + segment.deltaAngle * local;
point = new THREE.Vector2(
segment.center.x + Math.cos(angle) * segment.radius,
segment.center.y + Math.sin(angle) * segment.radius
);
const direction = Math.sign(segment.deltaAngle);
tangent = new THREE.Vector2(
direction * Math.sin(angle),
-direction * Math.cos(angle)
);
}
// Left normal points away from the pulley centers for this path.
const outward = new THREE.Vector2(-tangent.y, tangent.x);
return { point, tangent, outward };
}
// -------------------------------------------------------------------------
// Static voxel belt surface
// -------------------------------------------------------------------------
const beltBlockCount = Math.ceil(beltPath.length / 0.215);
const beltBlockSpacing = beltPath.length / beltBlockCount;
const beltBlocks = new THREE.InstancedMesh(
unitBox,
materials.belt,
beltBlockCount
);
beltBlocks.castShadow = true;
beltBlocks.receiveShadow = true;
for (let i = 0; i < beltBlockCount; i++) {
const s = (i + 0.5) * beltBlockSpacing;
const sample = sampleBeltPath(s);
const angle = Math.atan2(sample.tangent.y, sample.tangent.x);
dummy.position.set(
sample.point.x,
sample.point.y,
0.26
);
dummy.rotation.set(0, 0, angle);
dummy.scale.set(
beltBlockSpacing * 1.04,
0.145,
0.72
);
dummy.updateMatrix();
beltBlocks.setMatrixAt(i, dummy.matrix);
beltBlocks.setColorAt(
i,
new THREE.Color(i % 2 === 0 ? 0x26343b : 0x304047)
);
}
beltBlocks.instanceMatrix.needsUpdate = true;
if (beltBlocks.instanceColor) {
beltBlocks.instanceColor.needsUpdate = true;
}
scene.add(beltBlocks);
// -------------------------------------------------------------------------
// Voxel pulleys
// -------------------------------------------------------------------------
function createVoxelPulley(radius, bodyColor, rimColor) {
const group = new THREE.Group();
const cell = 0.235;
const bodyRadius = radius - 0.19;
const extent = Math.ceil(bodyRadius / cell);
const cells = [];
for (let x = -extent; x <= extent; x++) {
for (let y = -extent; y <= extent; y++) {
const px = x * cell;
const py = y * cell;
if (Math.hypot(px, py) <= bodyRadius) {
cells.push({ x: px, y: py, key: x + y });
}
}
}
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.66,
metalness: 0.12
});
const body = new THREE.InstancedMesh(
unitBox,
bodyMaterial,
cells.length
);
body.castShadow = true;
body.receiveShadow = true;
cells.forEach((cellData, i) => {
dummy.position.set(cellData.x, cellData.y, 0);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(cell * 0.94, cell * 0.94, 0.66);
dummy.updateMatrix();
body.setMatrixAt(i, dummy.matrix);
const variation = ((cellData.key % 4) + 4) % 4;
const color = new THREE.Color(bodyColor);
color.offsetHSL(0, 0, variation === 0 ? 0.035 : -0.018);
body.setColorAt(i, color);
});
body.instanceMatrix.needsUpdate = true;
if (body.instanceColor) {
body.instanceColor.needsUpdate = true;
}
group.add(body);
// Voxel rim/teeth. Their outer pitch radius equals the specified radius.
const rimCount = 48;
const rim = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: rimColor,
roughness: 0.58,
metalness: 0.2
}),
rimCount
);
rim.castShadow = true;
rim.receiveShadow = true;
for (let i = 0; i < rimCount; i++) {
const angle = (i / rimCount) * Math.PI * 2;
const radialDistance = radius - 0.14;
dummy.position.set(
Math.cos(angle) * radialDistance,
Math.sin(angle) * radialDistance,
0.03
);
dummy.rotation.set(0, 0, angle);
dummy.scale.set(0.16, 0.28, 0.72);
dummy.updateMatrix();
rim.setMatrixAt(i, dummy.matrix);
}
rim.instanceMatrix.needsUpdate = true;
group.add(rim);
// A square hub makes the rotation especially easy to read.
makeBox(
group,
materials.darkSteel,
{ x: 0, y: 0, z: 0.03 },
{ x: 0.62, y: 0.62, z: 0.82 }
);
makeBox(
group,
new THREE.MeshStandardMaterial({
color: rimColor,
roughness: 0.4,
metalness: 0.4
}),
{ x: 0, y: 0, z: 0.07 },
{ x: 0.22, y: 0.22, z: 0.91 }
);
scene.add(group);
return group;
}
const driverPulley = createVoxelPulley(
R_DRIVER,
0x229c98,
0x70d2c9
);
driverPulley.position.set(C_DRIVER.x, C_DRIVER.y, 0);
const drivenPulley = createVoxelPulley(
R_DRIVEN,
0xed815b,
0xffb58c
);
drivenPulley.position.set(C_DRIVEN.x, C_DRIVEN.y, 0);
// -------------------------------------------------------------------------
// Supports and voxel floor
// -------------------------------------------------------------------------
makeBox(
scene,
materials.base,
{ x: 0, y: FLOOR_Y - 0.17, z: 0 },
{ x: 16, y: 0.24, z: 10.5 }
);
const floorTileCountX = 21;
const floorTileCountZ = 13;
const floorTilePitch = 0.74;
const floorTiles = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
}),
floorTileCountX * floorTileCountZ
);
floorTiles.receiveShadow = true;
let tileIndex = 0;
for (let ix = 0; ix < floorTileCountX; ix++) {
for (let iz = 0; iz < floorTileCountZ; iz++) {
const x =
(ix - (floorTileCountX - 1) * 0.5) * floorTilePitch;
const z =
(iz - (floorTileCountZ - 1) * 0.5) * floorTilePitch;
dummy.position.set(x, FLOOR_Y + 0.015, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.69, 0.12, 0.69);
dummy.updateMatrix();
floorTiles.setMatrixAt(tileIndex, dummy.matrix);
const shade = 0.5 + ((ix * 7 + iz * 11) % 5) * 0.018;
floorTiles.setColorAt(
tileIndex,
new THREE.Color().setHSL(0.53, 0.10, shade)
);
tileIndex++;
}
}
floorTiles.instanceMatrix.needsUpdate = true;
if (floorTiles.instanceColor) {
floorTiles.instanceColor.needsUpdate = true;
}
scene.add(floorTiles);
function createSupport(center, radius) {
const baseWidth = radius * 1.55;
const topY = center.y - 0.12;
makeBox(
scene,
materials.darkSteel,
{
x: center.x,
y: FLOOR_Y + 0.18,
z: -0.65
},
{
x: baseWidth,
y: 0.24,
z: 1.15
}
);
makeBox(
scene,
materials.steel,
{
x: center.x,
y: (FLOOR_Y + 0.3 + topY) * 0.5,
z: -0.68
},
{
x: 0.34,
y: Math.max(0.2, topY - FLOOR_Y - 0.3),
z: 0.38
}
);
makeBeam(
scene,
materials.steel,
center.x - baseWidth * 0.37,
FLOOR_Y + 0.30,
center.x - 0.12,
topY,
-0.66,
0.22,
0.36
);
makeBeam(
scene,
materials.steel,
center.x + baseWidth * 0.37,
FLOOR_Y + 0.30,
center.x + 0.12,
topY,
-0.66,
0.22,
0.36
);
makeBox(
scene,
materials.darkSteel,
{
x: center.x,
y: center.y,
z: -0.2
},
{
x: 0.48,
y: 0.48,
z: 1.55
}
);
}
createSupport(C_DRIVER, R_DRIVER);
createSupport(C_DRIVEN, R_DRIVEN);
// Rear machine rail.
makeBox(
scene,
materials.darkSteel,
{ x: 0, y: FLOOR_Y + 0.18, z: -1.12 },
{ x: 7.8, y: 0.22, z: 0.28 }
);
// -------------------------------------------------------------------------
// 3D labels
// -------------------------------------------------------------------------
const driverLabel = makeLabelSprite(
"DRIVER",
`R = ${R_DRIVER.toFixed(2)} m`
);
driverLabel.position.set(C_DRIVER.x, 2.55, 1.0);
scene.add(driverLabel);
const drivenLabel = makeLabelSprite(
"DRIVEN",
`R = ${R_DRIVEN.toFixed(2)} m`
);
drivenLabel.position.set(C_DRIVEN.x, 2.03, 1.0);
scene.add(drivenLabel);
// -------------------------------------------------------------------------
// Moving belt markers
//
// Every marker uses the same path-distance offset. Therefore all markers
// have exactly the same linear speed, including on the pulley arcs.
// -------------------------------------------------------------------------
const markerCount = 24;
const markers = [];
for (let i = 0; i < markerCount; i++) {
const group = new THREE.Group();
makeBox(
group,
materials.marker,
{ x: 0, y: 0.115, z: 0 },
{ x: 0.19, y: 0.16, z: 0.76 }
);
makeBox(
group,
materials.markerStripe,
{ x: 0, y: 0.205, z: 0 },
{ x: 0.055, y: 0.045, z: 0.78 }
);
group.userData.pathOffset = (i / markerCount) * beltPath.length;
markers.push(group);
scene.add(group);
}
// -------------------------------------------------------------------------
// Animation and explicit no-slip coupling
// -------------------------------------------------------------------------
let playing = true;
let beltSpeed = 2.4; // linear speed, m/s
let beltTravel = 0; // accumulated path distance
let previousTime = performance.now();
const driverOmegaElement = document.getElementById("driverOmega");
const drivenOmegaElement = document.getElementById("drivenOmega");
const beltSpeedElement = document.getElementById("beltSpeed");
const ratioElement = document.getElementById("ratioValue");
const speedOutput = document.getElementById("speedOutput");
const speedInput = document.getElementById("speedInput");
const playButton = document.getElementById("playButton");
function updateReadouts() {
const driverOmega = beltSpeed / R_DRIVER;
const drivenOmega = beltSpeed / R_DRIVEN;
const ratio = R_DRIVER / R_DRIVEN;
driverOmegaElement.textContent = driverOmega.toFixed(2);
drivenOmegaElement.textContent = drivenOmega.toFixed(2);
beltSpeedElement.textContent = beltSpeed.toFixed(2);
ratioElement.textContent = `${ratio.toFixed(2)}:1`;
speedOutput.textContent = `${beltSpeed.toFixed(2)} m/s`;
}
updateReadouts();
speedInput.addEventListener("input", () => {
beltSpeed = Number(speedInput.value);
updateReadouts();
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
window.addEventListener("keydown", (event) => {
if (
event.code === "Space" &&
event.target.tagName !== "INPUT"
) {
event.preventDefault();
playButton.click();
}
});
function animate(time) {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
if (playing) {
beltTravel += beltSpeed * dt;
}
// EXPLICIT NO-SLIP COUPLING
//
// For a rigid belt with no slipping:
//
// v = |omega| R
// omega = -v / R
//
// Both pulleys turn in the same sense for this open-belt layout.
// Integrating angular velocity is equivalent to using beltTravel / R.
driverPulley.rotation.z = -beltTravel / R_DRIVER;
drivenPulley.rotation.z = -beltTravel / R_DRIVEN;
// All markers are shifted by the identical path distance. Their speed
// along straight sections and curved sections is therefore exactly v.
for (const marker of markers) {
const sample = sampleBeltPath(
marker.userData.pathOffset + beltTravel
);
marker.position.set(
sample.point.x + sample.outward.x * 0.11,
sample.point.y + sample.outward.y * 0.11,
0.65
);
marker.rotation.z = Math.atan2(
sample.tangent.y,
sample.tangent.x
);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
// -------------------------------------------------------------------------
// Camera controls implemented without Three.js addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.18, 0);
const defaultCamera = {
theta: 1.18,
phi: 1.10,
radius: 12.3,
target: cameraTarget.clone()
};
let cameraTheta = defaultCamera.theta;
let cameraPhi = defaultCamera.phi;
let cameraRadius = defaultCamera.radius;
let dragging = false;
let panning = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.cos(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.sin(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTheta = defaultCamera.theta;
cameraPhi = defaultCamera.phi;
cameraRadius = defaultCamera.radius;
cameraTarget.copy(defaultCamera.target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (panning) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const panScale = cameraRadius * 0.00125;
cameraTarget
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
} else {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.005,
0.45,
1.48
);
}
updateCamera();
});
function endPointerDrag(event) {
dragging = false;
panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
7,
19
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```