Prompt specification
Build or customize the Three.js 3D scene "Open Belt Around Two Pulleys" 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: Open Belt Around Two Pulleys
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/open-belt-around-two-pulleys-x2009
Scene Description Prompt:
Please use Three.js from cdnjs for a cutaway scene based on this idea: open belt around two pulleys. Model a belt around two different-radius pulleys with tangent straight segments. Show the contact arcs and keep the belt path continuous around both wheels. Return one self-contained HTML file.
Working Three.js Starter (open-belt-around-two-pulleys-x2009):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Open Belt Drive — Cutaway (Three.js)</title>
<style>
:root { --ink:#e8eef6; --dim:#9fb0c4; }
* { box-sizing:border-box; }
html,body { margin:0; height:100%; background:#0b0e13; overflow:hidden;
font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
canvas { display:block; }
#hud { position:fixed; inset:0; pointer-events:none; color:var(--ink); }
.panel { position:absolute; background:rgba(12,16,22,.72); border:1px solid rgba(140,170,205,.22);
border-radius:10px; padding:12px 14px; backdrop-filter: blur(6px); }
#title { top:16px; left:16px; max-width:340px; }
#title h1 { margin:0 0 4px; font-size:16px; letter-spacing:.06em; }
#title p { margin:0; font-size:12px; color:var(--dim); line-height:1.5; }
#legend { bottom:16px; left:16px; font-size:12px; }
#legend .row { display:flex; align-items:center; gap:8px; margin:5px 0; color:var(--dim); }
#legend .sw { width:22px; height:9px; border-radius:2px; }
#ctrl { bottom:16px; right:16px; pointer-events:auto; display:flex; flex-direction:column; gap:7px; }
#ctrl button { pointer-events:auto; font:inherit; font-size:12px; color:var(--ink); cursor:pointer;
background:rgba(24,32,44,.9); border:1px solid rgba(150,180,215,.28); border-radius:7px; padding:7px 11px; text-align:left; }
#ctrl button:hover { background:rgba(40,56,76,.95); border-color:rgba(160,200,240,.55); }
#ctrl button b { color:#ffd08a; font-weight:600; }
#hint { top:16px; right:16px; font-size:11px; color:var(--dim); text-align:right; line-height:1.6; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="hud">
<div class="panel" id="title">
<h1>OPEN BELT DRIVE — CUTAWAY</h1>
<p>Two pulleys of different radius joined by one continuous belt.
Straight tangent spans, wrap (contact) arcs and tangent points are computed
from the true belt geometry.</p>
</div>
<div class="panel" id="legend">
<div class="row"><span class="sw" style="background:#ffa73d"></span> belt in contact with a pulley (wrap arc)</div>
<div class="row"><span class="sw" style="background:#7d93ab"></span> free straight span (external tangent)</div>
<div class="row"><span class="sw" style="background:#ff7a1a"></span> sectioned (cut) face of pulley</div>
<div class="row"><span class="sw" style="background:#ffe45e"></span> highlighted contact arc</div>
</div>
<div class="panel" id="hint">drag = orbit · wheel = zoom<br>right-drag = pan · double-click = reset</div>
<div class="panel" id="ctrl">
<button id="bCut">Cutaway: <b>ON</b></button>
<button id="bArc">Contact arcs: <b>ON</b></button>
<button id="bMot">Motion: <b>ON</b></button>
<button id="bSpin">Auto-orbit: <b>OFF</b></button>
<button id="bReset">Reset view</button>
</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ *
* Scene setup
* ------------------------------------------------------------------ */
const canvas = document.getElementById('c');
const renderer = new THREE.WebGLRenderer({ canvas, antialias:true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b0e13);
scene.fog = new THREE.Fog(0x0b0e13, 22, 46);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 0.1, 200);
/* ------------------------------------------------------------------ *
* Belt geometry constants
* ------------------------------------------------------------------ */
const R1 = 1.0; // small pulley (driver)
const R2 = 1.8; // large pulley (driven)
const D = 6.0; // centre distance
const C1 = new THREE.Vector3(-D/2, 0, 0); // small pulley centre
const C2 = new THREE.Vector3( D/2, 0, 0); // large pulley centre
// external (open-belt) tangent construction
const a = (R1 - R2) / D; // n.x
const b = Math.sqrt(1 - a*a); // n.y
const NU = new THREE.Vector3(a, b, 0); // upper tangent normal
const NL = new THREE.Vector3(a, -b, 0); // lower tangent normal
const GAM = Math.atan2(b, a); // tangent-point polar angle
const A1 = C1.clone().addScaledVector(NU, R1); // tangent points
const A2 = C2.clone().addScaledVector(NU, R2);
const B1 = C1.clone().addScaledVector(NL, R1);
const B2 = C2.clone().addScaledVector(NL, R2);
const TH1 = 2*Math.PI - 2*GAM; // wrap angle, small pulley
const TH2 = 2*GAM; // wrap angle, large pulley
/* ------------------------------------------------------------------ *
* Materials
* ------------------------------------------------------------------ */
const matSteel = new THREE.MeshStandardMaterial({ color:0x9aa3ae, metalness:0.72, roughness:0.34 });
const matDark = new THREE.MeshStandardMaterial({ color:0x6c7683, metalness:0.66, roughness:0.42 });
const matCut = new THREE.MeshStandardMaterial({ color:0xff7a1a, metalness:0.05, roughness:0.55,
emissive:0x5a1c00, emissiveIntensity:0.55 });
const matHub = new THREE.MeshStandardMaterial({ color:0xb7bfca, metalness:0.85, roughness:0.22 });
const matShaft = new THREE.MeshStandardMaterial({ color:0xd6dde5, metalness:0.95, roughness:0.14 });
const matBase = new THREE.MeshStandardMaterial({ color:0x39414d, metalness:0.35, roughness:0.72 });
const matBearing= new THREE.MeshStandardMaterial({ color:0x4a5361, metalness:0.45, roughness:0.6 });
const matFloor = new THREE.MeshStandardMaterial({ color:0x171b22, metalness:0.1, roughness:0.95 });
const CUT_COL = new THREE.Color(0xff7a1a);
const STL_COL = new THREE.Color(0x9aa3ae);
const SPAN_COL= new THREE.Color(0x7d93ab);
const ARC_COL = new THREE.Color(0xffa73d);
/* ------------------------------------------------------------------ *
* Belt ribbon: sample the closed belt path, then sweep a rectangular
* cross-section (inner face rides the pulley groove).
* ------------------------------------------------------------------ */
const BELT_T = 0.10; // belt thickness (radial)
const BELT_W = 0.50; // belt width (axial)
const HW = BELT_W/2;
const samples = []; // {p, n, s, kind}
function push(p, n, kind){ samples.push({ p:p.clone(), n:n.clone(), s:0, kind }); }
function addSpan(p0, p1, n, seg, kind){
for (let i=0;i<seg;i++){
const t = i/seg;
push(new THREE.Vector3().lerpVectors(p0,p1,t), n, kind);
}
}
function addArc(c, r, a0, a1, seg, kind){
for (let i=0;i<seg;i++){
const t=i/seg, ang = a0 + (a1-a0)*t;
const n = new THREE.Vector3(Math.cos(ang), Math.sin(ang), 0);
push(new THREE.Vector3(c.x + r*Math.cos(ang), c.y + r*Math.sin(ang), 0), n, kind);
}
}
// order of travel: upper tangent -> big pulley (CW) -> lower tangent -> small pulley (CW)
addSpan(A1, A2, NU, 46, 'span'); // upper straight tangent
addArc (C2, R2, GAM, -GAM, 130, 'arc'); // wrap on large pulley
addSpan(B2, B1, NL, 46, 'span'); // lower straight tangent
addArc (C1, R1, -GAM, -GAM - TH1, 105, 'arc'); // wrap on small pulley
// close the loop
samples.push({ p:samples[0].p.clone(), n:samples[0].n.clone(), s:0, kind:samples[0].kind });
let LEN = 0;
for (let i=1;i<samples.length;i++) LEN += samples[i].p.distanceTo(samples[i-1].p);
samples[samples.length-1].s = LEN;
for (let i=1;i<samples.length;i++) samples[i].s = samples[i-1].s + samples[i].p.distanceTo(samples[i-1].p);
/* --- sweep a closed rectangular profile along the path --- */
function ribbonGeometry(path, profile, useColors){
const m = profile.length;
const pos=[], nor=[], uv=[], col=[];
const centroid = {n:0,z:0};
profile.forEach(p=>{ centroid.n += p.n/m; centroid.z += p.z/m; });
const outward = (k)=>{
const p0=profile[k], p1=profile[(k+1)%m];
const mid={n:(p0.n+p1.n)/2, z:(p0.z+p1.z)/2};
const dn=p1.n-p0.n, dz=p1.z-p0.z;
const c1={n:dz,z:-dn}, c2={n:-dz,z:dn};
const v={n:mid.n-centroid.n, z:mid.z-centroid.z};
return (c1.n*v.n + c1.z*v.z) >= 0 ? c1 : c2;
};
const ZAX = new THREE.Vector3(0,0,1);
const P=(i,k)=> path[i].p.clone()
.addScaledVector(path[i].n, profile[k].n)
.addScaledVector(ZAX, profile[k].z);
for (let i=0;i<path.length-1;i++){
for (let k=0;k<m;k++){
const k1=(k+1)%m;
const A=P(i,k), B=P(i,k1), C=P(i+1,k1), D=P(i+1,k);
const o = outward(k);
const want = path[i].n.clone().multiplyScalar(o.n).addScaledVector(ZAX,o.z).normalize();
const nrm = new THREE.Vector3().subVectors(B,A).cross(new THREE.Vector3().subVectors(C,A)).normalize();
const flip = nrm.dot(want) < 0;
const t1 = flip ? [A,C,B] : [A,B,C];
const t2 = flip ? [A,D,C] : [A,C,D];
const u0 = path[i].s/LEN, u1 = path[i+1].s/LEN;
const v0 = k/m, v1 = (k+1)/m;
const c0 = useColors ? colorOf(path[i].kind) : null;
const c1c= useColors ? colorOf(path[i+1].kind) : null;
const pushTri=(t,ua,ub,va,vb,ca,cb)=>{
for (const v of t){ pos.push(v.x,v.y,v.z); nor.push(nrm.x,nrm.y,nrm.z); }
uv.push(ua,va, ub,vb, ub,vb);
if (ca){ for(let q=0;q<3;q++) col.push(ca.r,ca.g,ca.b, cb.r,cb.g,cb.b); }
};
pushTri(t1, u0,u1, v0,v1, c0,c1c);
pushTri(t2, u0,u1, v0,v1, c0,c1c);
}
}
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(pos,3));
g.setAttribute('normal', new THREE.Float32BufferAttribute(nor,3));
g.setAttribute('uv', new THREE.Float32BufferAttribute(uv,2));
if (useColors) g.setAttribute('color', new THREE.Float32BufferAttribute(col,3));
return g;
}
function colorOf(kind){ return kind==='arc' ? ARC_COL : SPAN_COL; }
/* belt texture: fine woven stripes that scroll with the belt */
function beltTexture(){
const c=document.createElement('canvas'); c.width=256; c.height=128;
const x=c.getContext('2d');
x.fillStyle='#cfd4da'; x.fillRect(0,0,256,128);
x.fillStyle='rgba(255,255,255,0.16)';
for(let i=0;i<16;i++) x.fillRect(i*16,0,8,128);
x.fillStyle='rgba(40,45,55,0.16)';
for(let i=0;i<8;i++) x.fillRect(i*32+8,0,8,128);
x.strokeStyle='rgba(70,80,95,0.10)'; x.lineWidth=1;
for(let y=0;y<128;y+=6){ x.beginPath(); x.moveTo(0,y); x.lineTo(256,y); x.stroke(); }
const t=new THREE.CanvasTexture(c);
t.wrapS=t.wrapT=THREE.RepeatWrapping;
t.repeat.x=26; t.colorSpace=THREE.SRGBColorSpace; t.anisotropy=8;
return t;
}
const beltTex = beltTexture();
const beltMat = new THREE.MeshStandardMaterial({
vertexColors:true, map:beltTex, metalness:0.18, roughness:0.62, side:THREE.DoubleSide
});
const beltProfile = [ {n:0,z:-HW}, {n:0,z:HW}, {n:BELT_T,z:HW}, {n:BELT_T,z:-HW} ];
const belt = new THREE.Mesh(ribbonGeometry(samples, beltProfile, true), beltMat);
belt.castShadow = true; belt.receiveShadow = true;
scene.add(belt);
/* ------------------------------------------------------------------ *
* Highlight strips (contact arcs / tangent spans) drawn on the belt
* ------------------------------------------------------------------ */
function flatStrip(path, nOff, halfW){
const pos=[], idx=[];
for (let i=0;i<path.length;i++){
const p = path[i].p.clone().addScaledVector(path[i].n, nOff);
pos.push(p.x,p.y,p.z-HW*0+(-halfW), p.x,p.y,p.z+halfW);
}
for (let i=0;i<path.length-1;i++){
const a=i*2, b=a+1, c=a+2, d=a+3;
idx.push(a,c,d, a,d,b);
}
const g=new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(pos,3));
g.setIndex(idx);
g.computeVertexNormals();
return g;
}
function sliceKind(kind){
const out=[];
for(const s of samples){ if(s.kind===kind) out.push(s); }
return out;
}
const arcGroup = new THREE.Group(); scene.add(arcGroup);
const arcMat = new THREE.MeshBasicMaterial({ color:0xffe45e, side:THREE.DoubleSide, transparent:true, opacity:0.95 });
const spanMat = new THREE.MeshBasicMaterial({ color:0x63e0ff, side:THREE.DoubleSide, transparent:true, opacity:0.85 });
const arcSmall = new THREE.Mesh(flatStrip(sliceKind('arc'), BELT_T+0.006, 0.10), arcMat);
const arcBig = new THREE.Mesh(flatStrip(sliceKind('arc'), BELT_T+0.006, 0.10), arcMat);
arcGroup.add(arcSmall, arcBig);
// distinguish the two arcs: tint them per pulley
arcSmall.material = new THREE.MeshBasicMaterial({ color:0xffe45e, side:THREE.DoubleSide });
arcBig.material = new THREE.MeshBasicMaterial({ color:0xff9c3d, side:THREE.DoubleSide });
const spanGroup = new THREE.Group(); scene.add(spanGroup);
for (const s of sliceKind('span')) spanGroup.add(new THREE.Mesh(flatStrip([s], BELT_T+0.006, 0.055), spanMat));
// rebuild span strips properly (continuous runs)
spanGroup.clear();
{
const runs=[]; let cur=[];
for(const s of samples){ if(s.kind==='span'){ cur.push(s);} else { if(cur.length>1) runs.push(cur); cur=[]; } }
if(cur.length>1) runs.push(cur);
for(const r of runs) spanGroup.add(new THREE.Mesh(flatStrip(r, BELT_T+0.006, 0.05), spanMat));
}
/* ------------------------------------------------------------------ *
* Pulleys (with switchable cutaway)
* ------------------------------------------------------------------ */
const pulleyGroups = [];
function buildPulley(r, cx, label, theta){
const R_out = r + 0.22;
const R_in = r - 0.18;
const GF = r - 0.012; // groove floor radius
const W2 = 0.45; // half width
const GR0 = 0.11, GR1 = 0.34; // groove wall radii in z
const HUB_R = 0.30;
const g = new THREE.Group();
g.position.set(cx,0,0);
/* full solid of revolution (used in "uncut" mode) */
const fullProfile = [
[R_in,-W2],[R_in,W2],[R_out,W2],[R_out,GR1],[GF,GR0],[GF,-GR0],[R_out,-GR1],[R_out,-W2],[R_in,-W2]
].map(p=>new THREE.Vector2(p[0],p[1]));
const latheFull = new THREE.Mesh(new THREE.LatheGeometry(fullProfile, 96), matSteel);
latheFull.rotation.x = Math.PI/2;
latheFull.castShadow = latheFull.receiveShadow = true;
/* back half (cutaway) — closed profile, the z = 0 face is the section */
const backProfile = [
[R_in,-W2],[R_in,0],[GF,0],[GF,-GR0],[R_out,-GR1],[R_out,-W2],[R_in,-W2]
].map(p=>new THREE.Vector2(p[0],p[1]));
const latheBack = new THREE.Mesh(new THREE.LatheGeometry(backProfile, 96),
new THREE.MeshStandardMaterial({vertexColors:true,color:0xffffff,metalness:0.66,roughness:0.36}));
latheBack.rotation.x = Math.PI/2;
{
const p = latheBack.geometry.getAttribute('position');
const c = [];
for(let i=0;i<p.count;i++){
const isCut = Math.abs(p.getY(i)) < 1e-5;
const col = isCut ? CUT_COL : STL_COL;
c.push(col.r,col.g,col.b);
}
latheBack.geometry.setAttribute('color', new THREE.Float32BufferAttribute(c,3));
}
latheBack.castShadow = latheBack.receiveShadow = true;
/* hub */
const hubFull = new THREE.Mesh(new THREE.CylinderGeometry(HUB_R,HUB_R,2*W2,40), matHub);
hubFull.rotation.x = Math.PI/2; hubFull.castShadow = true;
const hubBack = new THREE.Mesh(new THREE.CylinderGeometry(HUB_R,HUB_R,W2,40,1,true), matHub);
hubBack.rotation.x = Math.PI/2; hubBack.position.z = -W2/2; hubBack.castShadow = true;
const hubCap = new THREE.Mesh(new THREE.CircleGeometry(HUB_R,40), matCut); // section face
hubCap.position.z = 0;
/* spokes */
const spokesFull=[], spokesBack=[];
const spokeLen = R_in - HUB_R;
for(let i=0;i<6;i++){
const ang = i*Math.PI/3 + 0.2;
const mk=(depth,z0,cut)=>{
const mats = [matDark,matDark,matDark,matDark, cut?matCut:matDark, matDark];
const b = new THREE.Mesh(new THREE.BoxGeometry(spokeLen, 0.16, depth), mats);
b.position.set(Math.cos(ang)*(HUB_R+spokeLen/2), Math.sin(ang)*(HUB_R+spokeLen/2), z0);
b.rotation.z = ang;
b.castShadow = true;
return b;
};
spokesFull.push(mk(2*W2-0.02, 0, false));
spokesBack.push(mk(W2-0.02, -W2/2-0.005, true));
}
const rotor = new THREE.Group();
rotor.add(latheFull, hubFull, ...spokesFull);
const cutRotor = new THREE.Group();
cutRotor.add(latheBack, hubBack, hubCap, ...spokesBack);
/* shaft (does not rotate with the rim visually is fine) */
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.11,0.11,3.4,24), matShaft);
shaft.rotation.x = Math.PI/2; shaft.castShadow = true;
/* bearing housing + pedestal */
const brg = new THREE.Mesh(new THREE.CylinderGeometry(0.30,0.30,1.1,28), matBearing);
brg.rotation.x = Math.PI/2; brg.position.z = -0.75; brg.castShadow = true;
const ped = new THREE.Mesh(new THREE.BoxGeometry(0.9, 1.5, 1.0), matBearing);
ped.position.set(0,-1.05,-0.75); ped.castShadow = ped.receiveShadow = true;
const foot = new THREE.Mesh(new THREE.BoxGeometry(1.3,0.22,1.4), matBase);
foot.position.set(0,-1.85,-0.75); foot.castShadow = foot.receiveShadow = true;
g.add(rotor, cutRotor, shaft, brg, ped, foot);
scene.add(g);
pulleyGroups.push({ g, rotor, cutRotor, r, cx, theta });
return g;
}
const p1 = buildPulley(R1, C1.x, 'small', -1);
const p2 = buildPulley(R2, C2.x, 'large', -1);
/* base plate + floor */
const plate = new THREE.Mesh(new THREE.BoxGeometry(9.6,0.22,2.6), matBase);
plate.position.set(0,-1.96,-0.4); plate.receiveShadow = true; plate.castShadow = true; scene.add(plate);
const floor = new THREE.Mesh(new THREE.PlaneGeometry(60,60), matFloor);
floor.rotation.x = -Math.PI/2; floor.position.y = -2.08; floor.receiveShadow = true; scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x2a3340, 0x1a212a);
grid.position.y = -2.07; scene.add(grid);
/* ------------------------------------------------------------------ *
* Annotations
* ------------------------------------------------------------------ */
function makeLabel(text, pos, color='#e8eef6', width=2.4, opts={}){
const c=document.createElement('canvas'); c.width=640; c.height=160;
const x=c.getContext('2d');
if(opts.bg!==false){
x.fillStyle='rgba(10,14,20,0.72)';
x.strokeStyle='rgba(150,185,220,0.35)'; x.lineWidth=3;
x.beginPath(); x.roundRect ? x.roundRect(4,26,632,108,14) : x.rect(4,26,632,108);
x.fill(); x.stroke();
}
x.font='600 46px ui-sans-serif, system-ui, sans-serif';
x.textAlign='center'; x.textBaseline='middle';
x.fillStyle=color; x.fillText(text, 320, 82);
const t=new THREE.CanvasTexture(c); t.colorSpace=THREE.SRGBColorSpace;
const sp=new THREE.Sprite(new THREE.SpriteMaterial({map:t,transparent:true,depthTest:false,depthWrite:false}));
sp.position.copy(pos); sp.scale.set(width, width/4, 1); sp.renderOrder = 20;
scene.add(sp);
return sp;
}
function rod(p0,p1,r,mat){
const d=new THREE.Vector3().subVectors(p1,p0); const len=d.length();
const m=new THREE.Mesh(new THREE.CylinderGeometry(r,r,len,12), mat);
m.position.copy(p0).addScaledVector(d,0.5);
m.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0), d.clone().normalize());
return m;
}
function coneAt(pos, dir, size, mat){
const m=new THREE.Mesh(new THREE.ConeGeometry(size, size*2.4, 18), mat);
m.position.copy(pos);
m.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0), dir.clone().normalize());
return m;
}
const matDim = new THREE.MeshBasicMaterial({color:0x6f8ba6});
const matDim2 = new THREE.MeshBasicMaterial({color:0xffc46b});
const matTP = new THREE.MeshBasicMaterial({color:0x6ff0b0});
/* tangent point markers */
const tpGroup = new THREE.Group(); scene.add(tpGroup);
for(const p of [A1,A2,B1,B2]){
const s=new THREE.Mesh(new THREE.SphereGeometry(0.055,16,12), matTP);
s.position.copy(p).setZ(BELT_T*0.5); tpGroup.add(s);
}
/* radial construction lines (centre -> tangent point) */
for(const [c,p] of [[C1,B1],[C1,A1],[C2,A2],[C2,B2]]){
const l=rod(c.clone().setZ(0), p.clone().setZ(0), 0.012, matDim);
scene.add(l);
}
/* centre distance dimension */
{
const y=-2.45;
const l=rod(new THREE.Vector3(C1.x,y,0), new THREE.Vector3(C2.x,y,0), 0.014, matDim2);
scene.add(l);
scene.add(coneAt(new THREE.Vector3(C1.x,y,0), new THREE.Vector3(-1,0,0), 0.07, matDim2));
scene.add(coneAt(new THREE.Vector3(C2.x,y,0), new THREE.Vector3(1,0,0), 0.07, matDim2));
scene.add(rod(new THREE.Vector3(C1.x,y-0.22,0), new THREE.Vector3(C1.x,y+0.22,0), 0.012, matDim2));
scene.add(rod(new THREE.Vector3(C2.x,y-0.22,0), new THREE.Vector3(C2.x,y+0.22,0), 0.012, matDim2));
scene.add(rod(new THREE.Vector3(C1.x,-1.95,0), new THREE.Vector3(C1.x,y,0), 0.008, matDim2));
scene.add(rod(new THREE.Vector3(C2.x,-1.95,0), new THREE.Vector3(C2.x,y,0), 0.008, matDim2));
}
/* radius dimensions */
for(const [c,r] of [[C1,R1],[C2,R2]]){
scene.add(rod(new THREE.Vector3(c.x,c.y,0), new THREE.Vector3(c.x,c.y-r,0), 0.012, matDim));
}
/* rotation arrows */
function rotationArrow(cx, r, mat){
const g=new THREE.Group();
const RR=r+0.52, L=1.5, th1=2.45;
const t=new THREE.Mesh(new THREE.TorusGeometry(RR,0.022,8,72,L), mat);
t.rotation.z = th1-L; g.add(t);
const th=th1-L;
const dir=new THREE.Vector3(Math.sin(th), -Math.cos(th), 0); // clockwise tangent
g.add(coneAt(new THREE.Vector3(cx+RR*Math.cos(th), RR*Math.sin(th), 0), dir, 0.085, mat));
scene.add(g);
return g;
}
rotationArrow(C1.x, R1, matDim2);
rotationArrow(C2.x, R2, matDim2);
/* labels */
makeLabel('DRIVER r = 1.00', new THREE.Vector3(C1.x, -1.55, 0.6), '#cfe0f2', 2.5);
makeLabel('DRIVEN r = 1.80', new THREE.Vector3(C2.x, -2.25, 0.6), '#cfe0f2', 2.5);
makeLabel('C = 6.00', new THREE.Vector3(0, -2.62, 0), '#ffc46b', 1.9);
makeLabel('TANGENT POINT', new THREE.Vector3(A2.x+0.35, A2.y+0.55, 0.3), '#8ff0c0', 2.4);
makeLabel('STRAIGHT SPAN (external tangent)', new THREE.Vector3(-0.2, 1.85, 0.2), '#9fd8ff', 3.4);
makeLabel('r = 1.00', new THREE.Vector3(C1.x-0.75, -0.55, 0.3), '#9fb0c4', 1.5);
makeLabel('r = 1.80', new THREE.Vector3(C2.x+0.85, -0.85, 0.3), '#9fb0c4', 1.5);
const labArc1 = makeLabel('CONTACT ARC 164.7°', new THREE.Vector3(C1.x-1.85, 0.55, 0.3), '#ffd66b', 2.9);
const labArc2 = makeLabel('CONTACT ARC 195.3°', new THREE.Vector3(C2.x+2.45, 0.35, 0.3), '#ffb066', 2.9);
/* ------------------------------------------------------------------ *
* Lights
* ------------------------------------------------------------------ */
scene.add(new THREE.HemisphereLight(0xbcd3ea, 0x20242c, 0.55));
const key = new THREE.DirectionalLight(0xffffff, 1.5);
key.position.set(5,9,7); key.castShadow = true;
key.shadow.mapSize.set(2048,2048);
const sc = key.shadow.camera; sc.left=-9; sc.right=9; sc.top=7; sc.bottom=-7; sc.near=1; sc.far=30;
key.shadow.bias = -0.0008;
scene.add(key);
const fill = new THREE.DirectionalLight(0x8fb6ff, 0.55); fill.position.set(-7,4,-6); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffd0a0, 0.45); rim.position.set(-2,-3,7); scene.add(rim);
/* ------------------------------------------------------------------ *
* Custom orbit camera (no addons)
* ------------------------------------------------------------------ */
const target = new THREE.Vector3(0,-0.35,0);
const sph = new THREE.Spherical(11.6, Math.PI/2 - 0.16, 0.30);
let autoSpin = false;
const pointers = new Map();
let dragging=false, lastX=0, lastY=0, panning=false, pinchDist=0;
function applyCamera(){
sph.phi = THREE.MathUtils.clamp(sph.phi, 0.15, Math.PI/2 + 0.42);
sph.radius = THREE.MathUtils.clamp(sph.radius, 4.5, 32);
const off = new THREE.Vector3().setFromSpherical(sph);
camera.position.copy(target).add(off);
camera.lookAt(target);
}
function resetView(){ sph.set(11.6, Math.PI/2-0.16, 0.30); target.set(0,-0.35,0); applyCamera(); }
canvas.addEventListener('contextmenu', e=>e.preventDefault());
canvas.addEventListener('pointerdown', e=>{
canvas.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, {x:e.clientX,y:e.clientY});
if(pointers.size===1){ dragging=true; panning=(e.button===2||e.shiftKey); lastX=e.clientX; lastY=e.clientY; }
});
canvas.addEventListener('pointermove', e=>{
if(!pointers.has(e.pointerId)) return;
pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});
if(pointers.size===2){
const [a,b]=[...pointers.values()];
const d=Math.hypot(a.x-b.x,a.y-b.y);
if(pinchDist) sph.radius *= pinchDist/d;
pinchDist=d; return;
}
if(!dragging) return;
const dx=e.clientX-lastX, dy=e.clientY-lastY;
lastX=e.clientX; lastY=e.clientY;
if(panning){
const right=new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up=new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
target.addScaledVector(right,-dx*0.0045*sph.radius/11).addScaledVector(up, dy*0.0045*sph.radius/11);
}else{
sph.theta -= dx*0.006;
sph.phi -= dy*0.005;
}
applyCamera();
});
const endPtr = e=>{ pointers.delete(e.pointerId); if(pointers.size<2) pinchDist=0; if(pointers.size===0) dragging=false; };
canvas.addEventListener('pointerup', endPtr);
canvas.addEventListener('pointercancel', endPtr);
canvas.addEventListener('wheel', e=>{ e.preventDefault(); sph.radius *= (1 + Math.sign(e.deltaY)*0.1); applyCamera(); }, {passive:false});
canvas.addEventListener('dblclick', resetView);
applyCamera();
/* ------------------------------------------------------------------ *
* UI
* ------------------------------------------------------------------ */
let cutaway=true, arcsOn=true, motion=true;
const bCut=document.getElementById('bCut'), bArc=document.getElementById('bArc'),
bMot=document.getElementById('bMot'), bSpin=document.getElementById('bSpin');
function refresh(){
pulleyGroups.forEach(p=>{ p.rotor.visible=!cutaway; p.cutRotor.visible=cutaway; });
arcGroup.visible = arcsOn; spanGroup.visible = arcsOn;
labArc1.visible = arcsOn; labArc2.visible = arcsOn;
bCut.innerHTML = 'Cutaway: <b>'+(cutaway?'ON':'OFF')+'</b>';
bArc.innerHTML = 'Contact arcs: <b>'+(arcsOn?'ON':'OFF')+'</b>';
bMot.innerHTML = 'Motion: <b>'+(motion?'ON':'OFF')+'</b>';
bSpin.innerHTML = 'Auto-orbit: <b>'+(autoSpin?'ON':'OFF')+'</b>';
}
bCut.onclick=()=>{cutaway=!cutaway;refresh();};
bArc.onclick=()=>{arcsOn=!arcsOn;refresh();};
bMot.onclick=()=>{motion=!motion;refresh();};
bSpin.onclick=()=>{autoSpin=!autoSpin;refresh();};
document.getElementById('bReset').onclick=resetView;
refresh();
/* ------------------------------------------------------------------ *
* Animation
* ------------------------------------------------------------------ */
const clock = new THREE.Clock();
let simT = 0;
const BELT_SPEED = 1.25;
function animate(){
const dt = Math.min(clock.getDelta(), 0.05);
if(motion){
simT += dt;
// belt surface scrolls; pulleys rotate clockwise (viewed from +Z)
beltTex.offset.x -= (BELT_SPEED*dt/LEN);
pulleyGroups.forEach(p=>{
const w = BELT_SPEED / p.r; // angular speed
p.rotor.rotation.z = -w*simT;
p.cutRotor.rotation.z = -w*simT;
});
}
if(autoSpin){ sph.theta += dt*0.12; applyCamera(); }
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```