Prompt specification
Build or customize the Three.js 3D scene "Bearing Rings and Rolling Elements" 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: Bearing Rings and Rolling Elements
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bearing-rings-and-rolling-elements-x2005
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts an enlarged ball bearing in technical cutaway. Show the inner ring, outer ring, evenly spaced balls, and a thin cage that separates them. Remove a wedge from the front of the outer ring so the raceway profile is visible, and place one extracted ball beside the assembly. Use steel-gray surfaces, a slightly darker cage, and a plain base. Let the viewer turn the inner ring slowly while the outer housing stays fixed; keep the rolling elements seated between their raceways. Focus on the permitted relative motion and geometric constraints, leaving detailed lubrication and load behavior outside this schematic model.
Working Three.js Starter (bearing-rings-and-rolling-elements-x2005):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ball Bearing — Technical Cutaway</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(15, 21, 27, 0.82);
--line: rgba(190, 205, 216, 0.17);
--text: #e3e9ed;
--muted: #9aa8b3;
--accent: #b9c9d2;
--cage: #56616a;
--good: #9fc8b2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 62% 35%, #26313a 0%, #111820 43%, #080d12 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-panel {
top: 22px;
left: 22px;
width: min(460px, calc(100vw - 44px));
padding: 18px 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.2vw, 29px);
font-weight: 620;
letter-spacing: -0.035em;
line-height: 1.12;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #c4ced5;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: #aab4bb;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.swatch.cage {
background: var(--cage);
}
.swatch.cut {
border-radius: 2px;
background: #6f7a82;
}
#metrics {
top: 22px;
right: 22px;
display: grid;
grid-template-columns: repeat(2, minmax(105px, 1fr));
gap: 1px;
overflow: hidden;
}
.metric {
min-width: 118px;
padding: 12px 14px;
background: rgba(14, 20, 26, 0.7);
}
.metric-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-variant-numeric: tabular-nums;
font-size: 17px;
font-weight: 620;
}
#status {
grid-column: 1 / -1;
display: flex;
align-items: center;
gap: 8px;
padding: 9px 14px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--good);
box-shadow: 0 0 12px rgba(159, 200, 178, 0.65);
}
#controls {
left: 22px;
bottom: 22px;
width: min(690px, calc(100vw - 44px));
padding: 15px 16px;
}
.control-row {
display: grid;
grid-template-columns: auto minmax(130px, 1fr) minmax(130px, 1fr) auto;
align-items: center;
gap: 15px;
}
.buttons {
display: flex;
gap: 7px;
}
button {
min-height: 36px;
padding: 0 13px;
border: 1px solid rgba(205, 217, 225, 0.22);
border-radius: 7px;
background: rgba(210, 222, 230, 0.08);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(220, 230, 237, 0.42);
background: rgba(210, 222, 230, 0.14);
}
button:active {
transform: translateY(1px);
}
#play {
min-width: 78px;
background: rgba(201, 214, 222, 0.16);
}
.slider-control {
min-width: 0;
}
.slider-label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.slider-label output {
color: #d6dee3;
font-variant-numeric: tabular-nums;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
-webkit-appearance: none;
background: rgba(190, 204, 214, 0.2);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #d5dfe5;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: #697781;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid #d5dfe5;
border-radius: 50%;
background: #697781;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}
.hint {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #8796a1;
font-size: 10px;
line-height: 1.5;
}
.hint strong {
color: #b8c4cc;
font-weight: 600;
}
#extract-label {
position: fixed;
z-index: 4;
top: 0;
left: 0;
padding: 6px 9px;
border-left: 2px solid #c3d0d8;
border-radius: 0 5px 5px 0;
background: rgba(12, 18, 23, 0.82);
color: #dbe3e8;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
opacity: 0;
transform: translate(-999px, -999px);
transition: opacity 160ms ease;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #0c1218;
color: #aebbc4;
font-size: 12px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
margin-bottom: 10px;
}
.legend {
padding-top: 10px;
}
#metrics {
top: auto;
right: 12px;
bottom: 190px;
grid-template-columns: repeat(2, 104px);
}
.metric {
min-width: 0;
padding: 9px 10px;
}
.metric-value {
font-size: 14px;
}
#controls {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px;
}
.control-row {
grid-template-columns: auto 1fr;
gap: 12px;
}
.slider-control {
grid-column: span 1;
}
#reset {
justify-self: end;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<section id="title-panel" class="panel">
<div class="eyebrow">Technical kinematic study</div>
<h1>Enlarged radial ball bearing</h1>
<p class="subtitle">
A front wedge exposes the outer raceway profile. The rear race land remains
in place so the rolling elements stay geometrically seated.
</p>
<div class="legend">
<span><i class="swatch"></i>Steel races and balls</span>
<span><i class="swatch cage"></i>Cage</span>
<span><i class="swatch cut"></i>Sectioned face</span>
</div>
</section>
<section id="metrics" class="panel" aria-label="Bearing state">
<div class="metric">
<span class="metric-label">Inner ring</span>
<strong id="inner-readout" class="metric-value">0.0°</strong>
</div>
<div class="metric">
<span class="metric-label">Cage</span>
<strong id="cage-readout" class="metric-value">0.0°</strong>
</div>
<div class="metric">
<span class="metric-label">Cage ratio</span>
<strong class="metric-value">0.3986</strong>
</div>
<div class="metric">
<span class="metric-label">Ball orbit</span>
<strong class="metric-value">R = 3.55</strong>
</div>
<div id="status">
<i id="status-dot"></i>
<span id="status-text">Running · outer ring fixed</span>
</div>
</section>
<section id="controls" class="panel" aria-label="Scene controls">
<div class="control-row">
<div class="buttons">
<button id="play" type="button">Pause</button>
<button id="reset" type="button">Reset</button>
</div>
<label class="slider-control" for="angle">
<span class="slider-label">
Inner-ring position
<output id="angle-output" for="angle">0°</output>
</span>
<input id="angle" type="range" min="0" max="360" step="0.1" value="0" />
</label>
<label class="slider-control" for="speed">
<span class="slider-label">
Drive speed
<output id="speed-output" for="speed">10.3°/s</output>
</span>
<input id="speed" type="range" min="0.05" max="0.60" step="0.01" value="0.18" />
</label>
<button id="reset-camera" type="button">Reset view</button>
</div>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Wheel / pinch</strong> to zoom ·
<strong>Space</strong> to pause · <strong>R</strong> to reset ·
<strong>C</strong> to reset the camera.
<br />
Ideal pitch-circle kinematics only: no lubrication, load distribution,
Hertzian contact deformation, or force analysis is represented.
</div>
</section>
<div id="extract-label">Extracted rolling element</div>
<div id="loading">Loading Three.js scene…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera and scene
// -------------------------------------------------------------------------
const viewport = document.querySelector("#viewport");
const loading = document.querySelector("#loading");
const extractLabel = document.querySelector("#extract-label");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive cutaway ball bearing");
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x10171d, 22, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, -0.25, 0);
const view = {
theta: 0.63,
phi: 1.18,
radius: 18.5,
homeRadius: 18.5,
touched: false
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.cos(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.sin(view.theta)
);
camera.lookAt(target);
}
function resetCamera() {
view.theta = 0.63;
view.phi = 1.18;
view.radius = view.homeRadius;
view.touched = false;
updateCamera();
}
// -------------------------------------------------------------------------
// Procedural studio environment, generated with core Three.js only
// -------------------------------------------------------------------------
function createEnvironment() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 384;
const ctx = canvas.getContext("2d");
const bg = ctx.createLinearGradient(0, 0, 0, canvas.height);
bg.addColorStop(0, "#9ba8b1");
bg.addColorStop(0.43, "#59646d");
bg.addColorStop(0.7, "#252c32");
bg.addColorStop(1, "#0c1014");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const panels = [
{ x: 50, w: 100, a: 0.9, color: "#ffffff" },
{ x: 205, w: 42, a: 0.55, color: "#dbe8ef" },
{ x: 430, w: 120, a: 0.72, color: "#f4f1ea" },
{ x: 640, w: 55, a: 0.5, color: "#b9d4e2" }
];
for (const p of panels) {
const gradient = ctx.createLinearGradient(p.x, 0, p.x + p.w, 0);
gradient.addColorStop(0, `rgba(0,0,0,0)`);
gradient.addColorStop(0.5, `rgba(255,255,255,${p.a})`);
gradient.addColorStop(1, `rgba(0,0,0,0)`);
ctx.fillStyle = gradient;
ctx.fillRect(p.x, 35, p.w, 235);
}
const floorGlow = ctx.createLinearGradient(0, 235, 0, 330);
floorGlow.addColorStop(0, "rgba(160,180,190,0.2)");
floorGlow.addColorStop(1, "rgba(0,0,0,0)");
ctx.fillStyle = floorGlow;
ctx.fillRect(0, 235, canvas.width, 95);
const texture = new THREE.CanvasTexture(canvas);
texture.mapping = THREE.EquirectangularReflectionMapping;
texture.colorSpace = THREE.SRGBColorSpace;
const pmrem = new THREE.PMREMGenerator(renderer);
const target = pmrem.fromEquirectangular(texture);
scene.environment = target.texture;
pmrem.dispose();
texture.dispose();
}
createEnvironment();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc9ddeb, 0x11161b, 1.35));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(8, 12, 15);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00015;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9fc9e5, 1.5);
fillLight.position.set(-10, 3, 7);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd7b2, 1.8);
rimLight.position.set(4, -7, 9);
scene.add(rimLight);
const pointLight = new THREE.PointLight(0xdcecf5, 34, 30, 2);
pointLight.position.set(1, 3, 8);
scene.add(pointLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const outerMaterial = new THREE.MeshStandardMaterial({
color: 0x87939c,
metalness: 0.86,
roughness: 0.27
});
const innerMaterial = new THREE.MeshStandardMaterial({
color: 0xa7b2ba,
metalness: 0.9,
roughness: 0.23
});
const ballMaterial = new THREE.MeshStandardMaterial({
color: 0xc1c9ce,
metalness: 0.94,
roughness: 0.16
});
const cageMaterial = new THREE.MeshStandardMaterial({
color: 0x30373d,
metalness: 0.72,
roughness: 0.37
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0x748089,
metalness: 0.78,
roughness: 0.31,
side: THREE.DoubleSide
});
const witnessMaterial = new THREE.MeshStandardMaterial({
color: 0x2b3339,
metalness: 0.62,
roughness: 0.4
});
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x171d23,
metalness: 0.08,
roughness: 0.88
});
// -------------------------------------------------------------------------
// Bearing dimensions. The bearing axis is Z; the front face is +Z.
// -------------------------------------------------------------------------
const PITCH_RADIUS = 3.55;
const BALL_RADIUS = 0.72;
const OUTER_RADIUS = 5.15;
const BORE_RADIUS = 1.55;
const INNER_SHOULDER_RADIUS = 3.16;
const OUTER_SHOULDER_RADIUS = 3.92;
const RACE_HALF_Z = 0.62;
const SHOULDER_Z = 0.76;
const RING_HALF_DEPTH = 0.95;
const FRONT_BAND_START = 0.12;
const BALL_COUNT = 14;
const BALL_SPACING = (Math.PI * 2) / BALL_COUNT;
// Camera-facing angular cutaway in the front axial band.
const WEDGE_CENTER = 0.64;
const WEDGE_WIDTH = 1.20;
const WEDGE_START = WEDGE_CENTER - WEDGE_WIDTH / 2;
const WEDGE_END = WEDGE_CENTER + WEDGE_WIDTH / 2;
// -------------------------------------------------------------------------
// Custom profile-revolved geometry
// -------------------------------------------------------------------------
function outerRaceCurve(zStart, zEnd, steps = 24) {
const points = [];
for (let i = 0; i <= steps; i++) {
const z = THREE.MathUtils.lerp(zStart, zEnd, i / steps);
const root = Math.max(0, BALL_RADIUS * BALL_RADIUS - z * z);
const r = PITCH_RADIUS + Math.sqrt(root);
points.push({ r, z });
}
return points;
}
function innerRaceCurve(zStart, zEnd, steps = 24) {
const points = [];
for (let i = 0; i <= steps; i++) {
const z = THREE.MathUtils.lerp(zStart, zEnd, i / steps);
const root = Math.max(0, BALL_RADIUS * BALL_RADIUS - z * z);
const r = PITCH_RADIUS - Math.sqrt(root);
points.push({ r, z });
}
return points;
}
function makeInnerRingProfile() {
const profile = [
{ r: BORE_RADIUS, z: RING_HALF_DEPTH },
{ r: BORE_RADIUS, z: -RING_HALF_DEPTH },
{ r: INNER_SHOULDER_RADIUS, z: -RING_HALF_DEPTH },
{ r: INNER_SHOULDER_RADIUS, z: -SHOULDER_Z }
];
profile.push(...innerRaceCurve(-RACE_HALF_Z, RACE_HALF_Z));
profile.push(
{ r: INNER_SHOULDER_RADIUS, z: SHOULDER_Z },
{ r: INNER_SHOULDER_RADIUS, z: RING_HALF_DEPTH }
);
return profile;
}
function makeOuterRearProfile() {
const profile = outerRaceCurve(FRONT_BAND_START, -RACE_HALF_Z);
profile.push(
{ r: OUTER_SHOULDER_RADIUS, z: -SHOULDER_Z },
{ r: OUTER_SHOULDER_RADIUS, z: -RING_HALF_DEPTH },
{ r: OUTER_RADIUS, z: -RING_HALF_DEPTH },
{ r: OUTER_RADIUS, z: FRONT_BAND_START }
);
return profile;
}
function makeOuterFrontProfile() {
const profile = [
{ r: OUTER_SHOULDER_RADIUS, z: RING_HALF_DEPTH },
{ r: OUTER_SHOULDER_RADIUS, z: SHOULDER_Z }
];
profile.push(...outerRaceCurve(RACE_HALF_Z, FRONT_BAND_START));
profile.push(
{ r: OUTER_RADIUS, z: FRONT_BAND_START },
{ r: OUTER_RADIUS, z: RING_HALF_DEPTH }
);
return profile;
}
function makeRevolvedGeometry(
profile,
thetaStart,
thetaEnd,
thetaSegments
) {
const positions = [];
const indices = [];
const profileCount = profile.length;
for (let i = 0; i < profileCount; i++) {
const p = profile[i];
for (let j = 0; j <= thetaSegments; j++) {
const theta = THREE.MathUtils.lerp(
thetaStart,
thetaEnd,
j / thetaSegments
);
positions.push(
p.r * Math.cos(theta),
p.r * Math.sin(theta),
p.z
);
}
}
const row = thetaSegments + 1;
for (let i = 0; i < profileCount; i++) {
const nextProfile = (i + 1) % profileCount;
for (let j = 0; j < thetaSegments; j++) {
const a = i * row + j;
const b = i * row + j + 1;
const c = nextProfile * row + j + 1;
const d = nextProfile * row + j;
indices.push(a, b, d);
indices.push(b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function makeCutCapGeometry(profile, theta) {
const contour = profile.map((p) => new THREE.Vector2(p.r, p.z));
const triangles = THREE.ShapeUtils.triangulateShape(contour, []);
const positions = [];
const indices = [];
for (const p of profile) {
positions.push(
p.r * Math.cos(theta),
p.r * Math.sin(theta),
p.z
);
}
for (const triangle of triangles) {
indices.push(triangle[0], triangle[1], triangle[2]);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeProfileEdge(profile, theta) {
const points = profile.map(
(p) =>
new THREE.Vector3(
p.r * Math.cos(theta),
p.r * Math.sin(theta),
p.z
)
);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0x303940,
transparent: true,
opacity: 0.82
});
return new THREE.LineLoop(geometry, material);
}
// -------------------------------------------------------------------------
// Assembly hierarchy
// -------------------------------------------------------------------------
const assemblyRoot = new THREE.Group();
assemblyRoot.position.y = 0.20;
scene.add(assemblyRoot);
const innerGroup = new THREE.Group();
const outerGroup = new THREE.Group();
const cageGroup = new THREE.Group();
assemblyRoot.add(innerGroup, outerGroup, cageGroup);
const innerRing = new THREE.Mesh(
makeRevolvedGeometry(
makeInnerRingProfile(),
-Math.PI,
Math.PI,
192
),
innerMaterial
);
innerRing.castShadow = true;
innerRing.receiveShadow = true;
innerGroup.add(innerRing);
// The complete rear band retains the spherical race contact beneath the balls.
const outerRear = new THREE.Mesh(
makeRevolvedGeometry(
makeOuterRearProfile(),
-Math.PI,
Math.PI,
192
),
outerMaterial
);
outerRear.castShadow = true;
outerRear.receiveShadow = true;
outerGroup.add(outerRear);
// Only the front axial band is sectioned, leaving the rear race land intact.
const frontProfile = makeOuterFrontProfile();
const remainingStart = WEDGE_END;
const remainingEnd = WEDGE_START + Math.PI * 2;
const outerFront = new THREE.Mesh(
makeRevolvedGeometry(
frontProfile,
remainingStart,
remainingEnd,
176
),
outerMaterial
);
outerFront.castShadow = true;
outerFront.receiveShadow = true;
outerGroup.add(outerFront);
for (const theta of [remainingStart, remainingEnd]) {
const cap = new THREE.Mesh(
makeCutCapGeometry(frontProfile, theta),
cutMaterial
);
cap.castShadow = true;
cap.receiveShadow = true;
outerGroup.add(cap);
outerGroup.add(makeProfileEdge(frontProfile, theta));
}
// -------------------------------------------------------------------------
// Thin cage: side rails and separator webs in the angular gaps
// -------------------------------------------------------------------------
function makeAnnulusGeometry(innerRadius, outerRadius, depth) {
const shape = new THREE.Shape();
shape.absarc(0, 0, outerRadius, 0, Math.PI * 2, false);
const hole = new THREE.Path();
hole.absarc(0, 0, innerRadius, 0, Math.PI * 2, true);
shape.holes.push(hole);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: 96,
steps: 1
});
geometry.translate(0, 0, -depth / 2);
return geometry;
}
const railGeometry = makeAnnulusGeometry(
PITCH_RADIUS - 0.12,
PITCH_RADIUS + 0.12,
0.045
);
for (const z of [-0.77, 0.77]) {
const rail = new THREE.Mesh(railGeometry, cageMaterial);
rail.position.z = z;
rail.castShadow = true;
rail.receiveShadow = true;
cageGroup.add(rail);
}
const separatorBodyGeometry = new THREE.BoxGeometry(0.62, 0.055, 0.64);
const separatorLinkGeometry = new THREE.BoxGeometry(0.075, 0.055, 0.46);
for (let i = 0; i < BALL_COUNT; i++) {
const theta = WEDGE_CENTER + BALL_SPACING * (i + 0.5);
const separator = new THREE.Group();
separator.rotation.z = theta;
const body = new THREE.Mesh(separatorBodyGeometry, cageMaterial);
body.position.x = PITCH_RADIUS;
body.castShadow = true;
separator.add(body);
for (const sign of [-1, 1]) {
const link = new THREE.Mesh(separatorLinkGeometry, cageMaterial);
link.position.set(PITCH_RADIUS, 0, sign * 0.55);
link.castShadow = true;
separator.add(link);
}
cageGroup.add(separator);
}
// -------------------------------------------------------------------------
// Rolling elements
// -------------------------------------------------------------------------
const ballGeometry = new THREE.SphereGeometry(BALL_RADIUS, 44, 28);
const ballMarkerGeometry = new THREE.CircleGeometry(0.060, 20);
const ballMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x3b444b,
metalness: 0.68,
roughness: 0.38,
side: THREE.DoubleSide
});
const rollingBalls = [];
function makeBall() {
const group = new THREE.Group();
const sphere = new THREE.Mesh(ballGeometry, ballMaterial);
sphere.castShadow = true;
sphere.receiveShadow = true;
group.add(sphere);
// A small witness mark makes the otherwise symmetric ball rotation visible.
const marker = new THREE.Mesh(ballMarkerGeometry, ballMarkerMaterial);
marker.position.x = BALL_RADIUS + 0.0015;
marker.rotation.y = Math.PI / 2;
group.add(marker);
return group;
}
for (let i = 0; i < BALL_COUNT; i++) {
const theta = WEDGE_CENTER + i * BALL_SPACING;
const pivot = new THREE.Group();
pivot.position.set(
PITCH_RADIUS * Math.cos(theta),
PITCH_RADIUS * Math.sin(theta),
0
);
pivot.rotation.z = theta;
const spin = makeBall();
pivot.add(spin);
cageGroup.add(pivot);
rollingBalls.push({ pivot, spin });
}
// Extracted ball on the base, outside the housing.
const extractedBall = makeBall();
extractedBall.position.set(-6.05, -4.43, 0.75);
extractedBall.rotation.set(0.15, -0.35, 0.2);
assemblyRoot.add(extractedBall);
// -------------------------------------------------------------------------
// Witness marks: inner mark rotates; outer mark remains stationary
// -------------------------------------------------------------------------
function addWitnessMark(parent, radius, z, angle, length, width, material) {
const group = new THREE.Group();
group.position.set(
radius * Math.cos(angle),
radius * Math.sin(angle),
z
);
group.rotation.z = angle;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, width, 0.026),
material
);
mesh.castShadow = true;
group.add(mesh);
parent.add(group);
}
addWitnessMark(
innerGroup,
2.28,
RING_HALF_DEPTH + 0.017,
0,
0.46,
0.085,
witnessMaterial
);
addWitnessMark(
outerGroup,
4.48,
RING_HALF_DEPTH + 0.017,
-1.82,
0.44,
0.075,
new THREE.MeshStandardMaterial({
color: 0xb7c0c7,
metalness: 0.78,
roughness: 0.3
})
);
// -------------------------------------------------------------------------
// Plain display base
// -------------------------------------------------------------------------
const base = new THREE.Mesh(
new THREE.CylinderGeometry(8.25, 8.55, 0.45, 112),
baseMaterial
);
base.position.y = -5.175;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
// -------------------------------------------------------------------------
// Kinematic model
//
// Outer race fixed:
// cage ratio = (pitch radius - ball radius) / (2 * pitch radius)
//
// Relative ball spin is chosen so the ideal spherical contact points have
// zero tangential velocity at the stationary outer race. The same relation
// satisfies the inner contact for the commanded inner-ring speed.
// -------------------------------------------------------------------------
const CAGE_RATIO =
(PITCH_RADIUS - BALL_RADIUS) / (2 * PITCH_RADIUS);
let driveAngle = 0;
let speed = 0.18;
let spinning = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const angleInput = document.querySelector("#angle");
const speedInput = document.querySelector("#speed");
const angleOutput = document.querySelector("#angle-output");
const speedOutput = document.querySelector("#speed-output");
const playButton = document.querySelector("#play");
const innerReadout = document.querySelector("#inner-readout");
const cageReadout = document.querySelector("#cage-readout");
const statusText = document.querySelector("#status-text");
const statusDot = document.querySelector("#status-dot");
function positiveModulo(value, modulus) {
return ((value % modulus) + modulus) % modulus;
}
function updateControlState() {
const innerDegrees = positiveModulo(
THREE.MathUtils.radToDeg(driveAngle),
360
);
const cageDegrees = positiveModulo(
THREE.MathUtils.radToDeg(driveAngle * CAGE_RATIO),
360
);
angleInput.value = innerDegrees.toFixed(1);
angleOutput.textContent = `${innerDegrees.toFixed(1)}°`;
innerReadout.textContent = `${innerDegrees.toFixed(1)}°`;
cageReadout.textContent = `${cageDegrees.toFixed(1)}°`;
speedOutput.textContent = `${THREE.MathUtils.radToDeg(speed).toFixed(1)}°/s`;
playButton.textContent = spinning ? "Pause" : "Play";
statusText.textContent = spinning
? "Running · outer ring fixed"
: "Paused · geometry constrained";
statusDot.style.background = spinning ? "#9fc8b2" : "#c0a878";
}
playButton.addEventListener("click", () => {
spinning = !spinning;
updateControlState();
});
angleInput.addEventListener("input", () => {
spinning = false;
driveAngle = THREE.MathUtils.degToRad(Number(angleInput.value));
updateControlState();
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
updateControlState();
});
document.querySelector("#reset").addEventListener("click", () => {
driveAngle = 0;
spinning = true;
resetCamera();
updateControlState();
});
document.querySelector("#reset-camera").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.code === "Space") {
event.preventDefault();
spinning = !spinning;
updateControlState();
}
if (event.key.toLowerCase() === "r") {
driveAngle = 0;
spinning = true;
resetCamera();
updateControlState();
}
if (event.key.toLowerCase() === "c") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom and two-pointer pinch
// -------------------------------------------------------------------------
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
view.touched = true;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
view.theta -= dx * 0.005;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.005,
0.42,
2.45
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0 && distance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (previousPinchDistance / distance),
10,
38
);
}
previousPinchDistance = distance;
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("lostpointercapture", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.touched = true;
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
10,
38
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Label projection
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateExtractedLabel() {
extractedBall.getWorldPosition(projected);
projected.y += 0.47;
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
extractLabel.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
extractLabel.style.transform =
`translate(${Math.min(x + 17, window.innerWidth - 190)}px, ` +
`${Math.max(12, y - 35)}px)`;
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.fov = camera.aspect < 0.8 ? 46 : 38;
camera.updateProjectionMatrix();
view.homeRadius = Math.max(
18.5,
8.8 /
(Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) *
camera.aspect)
);
if (!view.touched) {
view.radius = view.homeRadius;
}
updateCamera();
}
window.addEventListener("resize", onResize);
onResize();
updateControlState();
let previousTime = performance.now();
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (spinning) {
driveAngle += speed * dt;
}
const cageAngle = driveAngle * CAGE_RATIO;
// The parent cage already contributes angular velocity to each ball.
// This additional relative spin satisfies ideal no-slip at the outer race.
const relativeBallSpin =
-driveAngle * CAGE_RATIO * (PITCH_RADIUS / BALL_RADIUS + 1);
innerGroup.rotation.z = driveAngle;
outerGroup.rotation.z = 0;
cageGroup.rotation.z = cageAngle;
for (const ball of rollingBalls) {
ball.spin.rotation.z = relativeBallSpin;
}
updateControlState();
updateExtractedLabel();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
loading.style.display = "none";
requestAnimationFrame(animate);
</script>
</body>
</html>
```