Prompt specification
Build or customize the Three.js 3D scene "Lathed Spindle Profile Cutaway" 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: Lathed Spindle Profile Cutaway
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lathed-spindle-profile-cutaway-x2065
Scene Description Prompt:
A lathed spindle cutaway beside its generating profile and rotation axis, preserving radii and shoulders. Three.js from cdnjs, one HTML file.
Working Three.js Starter (lathed-spindle-profile-cutaway-x2065):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lathed Spindle — Sectioned Solid of Revolution</title>
<style>
:root {
--cyan: #62e6dc;
--amber: #f3b562;
--ink: #dcecf5;
--muted: #829baa;
--panel: rgba(7, 19, 31, 0.76);
--line: rgba(111, 194, 207, 0.19);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 35%, rgba(30, 93, 111, 0.18), transparent 34%),
radial-gradient(circle at 20% 55%, rgba(29, 75, 101, 0.15), transparent 38%),
linear-gradient(145deg, #07111d 0%, #081724 48%, #050c14 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
touch-action: none;
outline: none;
}
.ui {
position: absolute;
z-index: 10;
pointer-events: none;
}
header {
top: 28px;
left: 30px;
max-width: 410px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--cyan);
box-shadow: 0 0 10px rgba(98, 230, 220, 0.6);
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 43px);
font-weight: 530;
letter-spacing: -0.035em;
line-height: 1.02;
}
header p {
max-width: 365px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.status {
top: 28px;
right: 30px;
display: flex;
gap: 8px;
align-items: center;
}
.chip {
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
color: #9fb6c4;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.chip.live {
color: var(--cyan);
}
.live-dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px var(--cyan);
}
.legend {
left: 30px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 10px 18px;
max-width: 490px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(7, 18, 29, 0.66);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #9bb0bd;
font-size: 9px;
font-weight: 600;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.swatch {
width: 13px;
height: 3px;
border-radius: 3px;
background: #8199ab;
}
.swatch.section { background: var(--amber); }
.swatch.bore { background: #395367; }
.swatch.profile { background: var(--cyan); }
.controls {
right: 30px;
bottom: 28px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
color: #aec2ce;
font: inherit;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}
button:hover,
button.active {
border-color: rgba(98, 230, 220, 0.55);
background: rgba(21, 66, 76, 0.62);
color: var(--cyan);
}
.hint {
margin-right: 5px;
color: #627c8b;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#leaders,
#labels {
position: absolute;
inset: 0;
z-index: 5;
width: 100%;
height: 100%;
overflow: hidden;
pointer-events: none;
}
.callout {
position: absolute;
padding: 5px 7px;
border-left: 1px solid rgba(98, 230, 220, 0.68);
background: rgba(5, 15, 24, 0.73);
color: #a9c0cd;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.11em;
line-height: 1.25;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(5px);
}
.callout.section-callout {
border-color: var(--amber);
color: #e5c396;
}
.callout.profile-callout {
border-color: var(--cyan);
color: #9be9e3;
}
#loading {
position: absolute;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #07111d;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
max-width: 290px;
}
header p { display: none; }
.status { top: 18px; right: 18px; }
.status .chip:first-child { display: none; }
.legend { left: 18px; bottom: 68px; max-width: 320px; }
.controls { right: 18px; bottom: 18px; }
.hint { display: none; }
.callout.secondary { display: none; }
.chip { padding: 8px; }
}
</style>
</head>
<body>
<div id="stage"></div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<header class="ui">
<div class="eyebrow">Metrology / Lathe 04</div>
<h1>Lathed spindle</h1>
<p>
Sectioned solid of revolution with a stepped through-bore. External radii,
bearing shoulders, drive flange, and taper are carried directly from the
adjacent generating profile.
</p>
</header>
<div class="status ui">
<div class="chip">Orthographic study</div>
<div class="chip live"><span class="live-dot"></span>Live cutaway</div>
</div>
<div class="legend ui">
<div class="legend-item"><span class="swatch"></span>Turned surface</div>
<div class="legend-item"><span class="swatch section"></span>Section face</div>
<div class="legend-item"><span class="swatch bore"></span>Stepped bore</div>
<div class="legend-item"><span class="swatch profile"></span>Generating profile</div>
</div>
<div class="controls ui">
<span class="hint">Drag orbit · Shift/right drag pan · Wheel zoom</span>
<button id="spin" type="button">Auto rotate</button>
<button id="reset" type="button">Reset</button>
</div>
<div id="loading">Building section model…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const labelLayer = document.getElementById("labels");
const leaderSvg = document.getElementById("leaders");
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(0x07111d, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x07111d, 24, 48);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
camera.position.set(10, 4, 14);
const view = {
theta: 0.62,
elevation: 0.18,
radius: 18,
zoom: 1,
target: new THREE.Vector3(0.85, 0, 0)
};
const initialView = {
theta: view.theta,
elevation: view.elevation,
radius: view.radius,
zoom: view.zoom,
target: view.target.clone()
};
function updateCamera() {
const horizontal = Math.cos(view.elevation);
camera.position.set(
view.target.x + view.radius * Math.sin(view.theta) * horizontal,
view.target.y + view.radius * Math.sin(view.elevation),
view.target.z + view.radius * Math.cos(view.theta) * horizontal
);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function makeEnvironment() {
const faces = [];
for (let i = 0; i < 6; i++) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 128;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 128, 128);
gradient.addColorStop(0, "#0d1722");
gradient.addColorStop(0.48, "#30495b");
gradient.addColorStop(1, "#07111b");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 128, 128);
ctx.fillStyle = "rgba(220,246,255,0.62)";
ctx.fillRect(17, 5, 13, 118);
ctx.fillStyle = "rgba(79,219,211,0.24)";
ctx.fillRect(86, 0, 22, 128);
faces.push(canvas);
}
const cube = new THREE.CubeTexture(faces);
cube.colorSpace = THREE.SRGBColorSpace;
cube.needsUpdate = true;
return cube;
}
scene.environment = makeEnvironment();
scene.add(new THREE.HemisphereLight(0x9cc9e3, 0x081019, 1.2));
const keyLight = new THREE.DirectionalLight(0xe6f5ff, 3.0);
keyLight.position.set(-5, 10, 8);
keyLight.target.position.set(-2.5, 0, 0);
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 = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.PointLight(0x42d9d1, 22, 18, 2);
rimLight.position.set(5, 3, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb96f, 10, 12, 2);
warmLight.position.set(-1, 0, 4);
scene.add(warmLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x06101a,
roughness: 0.96,
metalness: 0.02,
transparent: true,
opacity: 0.82
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -4.96;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(
34,
68,
0x1a5265,
0x102d3d
);
grid.position.y = -4.945;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const outerProfile = [
[1.02, -4.78],
[1.02, -4.38],
[1.42, -4.16],
[1.55, -4.02],
[1.55, -3.42],
[1.92, -3.18],
[1.98, -2.98],
[1.98, -2.30],
[1.58, -2.00],
[1.58, -0.92],
[1.84, -0.66],
[1.90, -0.46],
[1.90, 0.68],
[1.50, 0.98],
[1.48, 1.18],
[1.48, 1.96],
[1.14, 2.20],
[1.10, 2.38],
[1.10, 3.56],
[0.84, 3.82],
[0.82, 4.02],
[0.82, 4.68]
];
const innerProfile = [
[0.32, -4.78],
[0.32, -1.80],
[0.66, -1.48],
[0.68, -1.20],
[0.68, 0.86],
[0.32, 1.18],
[0.32, 4.68]
];
const spindle = new THREE.Group();
spindle.position.set(-3.0, 0.05, 0);
scene.add(spindle);
const cutCenter = 0.62;
const cutAngle = THREE.MathUtils.degToRad(104);
const phiStart = cutCenter + cutAngle / 2;
const phiLength = Math.PI * 2 - cutAngle;
const turnedMaterial = new THREE.MeshStandardMaterial({
color: 0x849aac,
metalness: 0.78,
roughness: 0.29
});
const boreMaterial = new THREE.MeshStandardMaterial({
color: 0x172c3b,
metalness: 0.66,
roughness: 0.48,
side: THREE.DoubleSide
});
const sectionMaterial = new THREE.MeshStandardMaterial({
color: 0xd9984e,
emissive: 0x4b2506,
emissiveIntensity: 0.18,
metalness: 0.56,
roughness: 0.38,
side: THREE.DoubleSide
});
const endMaterial = new THREE.MeshStandardMaterial({
color: 0x9aabb8,
metalness: 0.8,
roughness: 0.3,
side: THREE.DoubleSide
});
const outerPoints = outerProfile.map(
([radius, axial]) => new THREE.Vector2(radius, axial)
);
const innerPoints = innerProfile.map(
([radius, axial]) => new THREE.Vector2(radius, axial)
);
const outerSurface = new THREE.Mesh(
new THREE.LatheGeometry(outerPoints, 160, phiStart, phiLength),
turnedMaterial
);
outerSurface.castShadow = true;
outerSurface.receiveShadow = true;
spindle.add(outerSurface);
const innerSurface = new THREE.Mesh(
new THREE.LatheGeometry(innerPoints, 160, phiStart, phiLength),
boreMaterial
);
innerSurface.castShadow = true;
innerSurface.receiveShadow = true;
spindle.add(innerSurface);
function annularSector(innerRadius, outerRadius, y) {
const positions = [];
const indices = [];
const segments = 128;
for (let i = 0; i <= segments; i++) {
const angle = phiStart + (i / segments) * phiLength;
positions.push(
innerRadius * Math.sin(angle), y, innerRadius * Math.cos(angle),
outerRadius * Math.sin(angle), y, outerRadius * Math.cos(angle)
);
if (i < segments) {
const a = i * 2;
const b = (i + 1) * 2;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const bottomRing = new THREE.Mesh(
annularSector(0.32, 1.02, -4.78),
endMaterial
);
bottomRing.castShadow = true;
spindle.add(bottomRing);
const topRing = new THREE.Mesh(
annularSector(0.32, 0.82, 4.68),
endMaterial
);
topRing.castShadow = true;
spindle.add(topRing);
function makeCutFace(angle) {
const shape = new THREE.Shape();
shape.moveTo(outerProfile[0][0], outerProfile[0][1]);
for (let i = 1; i < outerProfile.length; i++) {
shape.lineTo(outerProfile[i][0], outerProfile[i][1]);
}
for (let i = innerProfile.length - 1; i >= 0; i--) {
shape.lineTo(innerProfile[i][0], innerProfile[i][1]);
}
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
geometry.rotateY(angle - Math.PI / 2);
const mesh = new THREE.Mesh(geometry, sectionMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
spindle.add(mesh);
}
makeCutFace(phiStart);
makeCutFace(phiStart + phiLength);
function profileBoundaryPoints(angle) {
const points = [];
outerProfile.forEach(([radius, axial]) => {
points.push(new THREE.Vector3(
radius * Math.sin(angle),
axial,
radius * Math.cos(angle)
));
});
for (let i = innerProfile.length - 1; i >= 0; i--) {
const [radius, axial] = innerProfile[i];
points.push(new THREE.Vector3(
radius * Math.sin(angle),
axial,
radius * Math.cos(angle)
));
}
points.push(points[0].clone());
return points;
}
const boundaryMaterial = new THREE.LineBasicMaterial({
color: 0xffd49a,
transparent: true,
opacity: 0.92
});
[phiStart, phiStart + phiLength].forEach(angle => {
const geometry = new THREE.BufferGeometry().setFromPoints(
profileBoundaryPoints(angle)
);
spindle.add(new THREE.Line(geometry, boundaryMaterial));
});
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -5.22, 0),
new THREE.Vector3(0, 5.22, 0)
]);
const spindleAxis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x6edfd7,
dashSize: 0.14,
gapSize: 0.11,
transparent: true,
opacity: 0.34,
depthTest: false
})
);
spindleAxis.computeLineDistances();
spindleAxis.renderOrder = 8;
spindle.add(spindleAxis);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(2.18, 2.32, 0.14, 96),
new THREE.MeshStandardMaterial({
color: 0x102534,
metalness: 0.58,
roughness: 0.52
})
);
plinth.position.y = -4.88;
plinth.receiveShadow = true;
spindle.add(plinth);
for (const radius of [2.55, 3.05]) {
const points = [];
for (let i = 0; i <= 128; i++) {
const a = (i / 128) * Math.PI * 2;
points.push(new THREE.Vector3(
Math.cos(a) * radius,
-4.935,
Math.sin(a) * radius
));
}
const circle = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: radius > 3 ? 0x163c4b : 0x26586a,
transparent: true,
opacity: 0.48
})
);
spindle.add(circle);
}
// Billboarding profile plate.
const profileGroup = new THREE.Group();
profileGroup.position.set(4.35, 0.05, 0);
scene.add(profileGroup);
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(6.35, 11.35),
new THREE.MeshBasicMaterial({
color: 0x0b1d2b,
transparent: true,
opacity: 0.58,
depthWrite: false
})
);
panel.position.set(0.65, 0, -0.08);
profileGroup.add(panel);
const profileScale = 1.18;
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 10);
const jointGeometry = new THREE.SphereGeometry(1, 12, 8);
function makePolyline(points, material, radius = 0.014) {
const group = new THREE.Group();
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (length < 0.0001) continue;
const segment = new THREE.Mesh(unitCylinder, material);
segment.position.copy(a).add(b).multiplyScalar(0.5);
segment.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
segment.scale.set(radius, length, radius);
group.add(segment);
}
points.forEach(point => {
const joint = new THREE.Mesh(jointGeometry, material);
joint.position.copy(point);
joint.scale.setScalar(radius * 1.12);
group.add(joint);
});
profileGroup.add(group);
return group;
}
const profileMaterial = new THREE.MeshStandardMaterial({
color: 0x62e6dc,
emissive: 0x0b5a56,
emissiveIntensity: 0.68,
metalness: 0.28,
roughness: 0.32
});
const borderMaterial = new THREE.MeshStandardMaterial({
color: 0x1d5262,
emissive: 0x061b22,
emissiveIntensity: 0.3,
metalness: 0.2,
roughness: 0.6
});
const panelBorder = [
new THREE.Vector3(-2.52, -5.66, 0),
new THREE.Vector3(3.82, -5.66, 0),
new THREE.Vector3(3.82, 5.66, 0),
new THREE.Vector3(-2.52, 5.66, 0),
new THREE.Vector3(-2.52, -5.66, 0)
];
makePolyline(panelBorder, borderMaterial, 0.009);
function dashedLine(points, color, opacity = 0.4, dash = 0.11, gap = 0.08) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: dash,
gapSize: gap,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
profileGroup.add(line);
return line;
}
dashedLine(
[
new THREE.Vector3(0, -5.28, 0.015),
new THREE.Vector3(0, 5.28, 0.015)
],
0x78a9b8,
0.62,
0.13,
0.09
);
const outerProfileLine = outerProfile.map(
([radius, axial]) => new THREE.Vector3(radius * profileScale, axial, 0.025)
);
makePolyline(outerProfileLine, profileMaterial, 0.021);
dashedLine(
outerProfile.map(
([radius, axial]) =>
new THREE.Vector3(-radius * profileScale, axial, 0.012)
),
0x3b7181,
0.36
);
dashedLine(
innerProfile.map(
([radius, axial]) =>
new THREE.Vector3(radius * profileScale, axial, 0.018)
),
0x7294a6,
0.58,
0.08,
0.065
);
const shoulderLevels = [-2.30, -0.66, 0.98, 2.20];
shoulderLevels.forEach(y => {
dashedLine(
[
new THREE.Vector3(-2.35, y, -0.005),
new THREE.Vector3(2.35, y, -0.005)
],
0x376979,
0.24,
0.09,
0.075
);
});
function addDimension(y, radius) {
const x = radius * profileScale;
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(0, y, 0.035),
x,
0x62e6dc,
0.14,
0.075
);
profileGroup.add(arrow);
makePolyline(
[
new THREE.Vector3(x, y - 0.09, 0.035),
new THREE.Vector3(x, y + 0.09, 0.035)
],
profileMaterial,
0.008
);
}
addDimension(-2.65, 1.98);
addDimension(0.10, 1.90);
addDimension(1.60, 1.48);
addDimension(3.00, 1.10);
const labels = [];
function addLabel(text, parent, localAnchor, offset, className = "") {
const element = document.createElement("div");
element.className = `callout ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", className.includes("section")
? "rgba(243,181,98,.58)"
: "rgba(98,230,220,.48)");
line.setAttribute("stroke-width", "1");
leaderSvg.appendChild(line);
const dot = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
dot.setAttribute("r", "2");
dot.setAttribute("fill", className.includes("section")
? "#f3b562"
: "#62e6dc");
leaderSvg.appendChild(dot);
labels.push({
element,
line,
dot,
parent,
local: new THREE.Vector3(...localAnchor),
offset
});
}
addLabel(
"01 · Bearing shoulder",
spindle,
[1.90, 0.82, 0],
[92, -32],
"secondary"
);
addLabel(
"02 · Drive flange",
spindle,
[1.98, -2.85, 0],
[105, 24]
);
addLabel(
"03 · Tapered nose",
spindle,
[0.82, 3.90, 0],
[82, -28],
"secondary"
);
addLabel(
"Stepped through-bore",
spindle,
[0.68, 0.0, 0],
[-112, 26],
"secondary"
);
const sectionAnchor = [
1.42 * Math.sin(phiStart),
1.12,
1.42 * Math.cos(phiStart)
];
addLabel(
"Cutaway section · 104°",
spindle,
sectionAnchor,
[-92, 48],
"section-callout"
);
addLabel(
"Generating profile",
profileGroup,
[0.72, 5.42, 0.08],
[-8, -15],
"profile-callout"
);
addLabel(
"Rotation axis",
profileGroup,
[0, -5.30, 0.08],
[26, 24],
"profile-callout"
);
addLabel(
"R1.98",
profileGroup,
[1.98 * profileScale * 0.57, -2.65, 0.08],
[31, -10],
"profile-callout secondary"
);
addLabel(
"R1.90",
profileGroup,
[1.90 * profileScale * 0.57, 0.10, 0.08],
[31, -10],
"profile-callout secondary"
);
addLabel(
"R1.48",
profileGroup,
[1.48 * profileScale * 0.57, 1.60, 0.08],
[30, -10],
"profile-callout secondary"
);
addLabel(
"R1.10",
profileGroup,
[1.10 * profileScale * 0.57, 3.00, 0.08],
[30, -10],
"profile-callout secondary"
);
addLabel(
"Shoulder datums",
profileGroup,
[2.48, 1.62, 0.08],
[40, 4],
"profile-callout secondary"
);
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
const projected = new THREE.Vector3();
labels.forEach(label => {
projected.copy(label.local);
label.parent.localToWorld(projected);
projected.project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const labelX = x + label.offset[0];
const labelY = y + label.offset[1];
label.element.style.left = `${labelX}px`;
label.element.style.top = `${labelY}px`;
label.element.style.opacity = visible ? "1" : "0";
label.line.setAttribute("x1", x);
label.line.setAttribute("y1", y);
label.line.setAttribute("x2", labelX);
label.line.setAttribute("y2", labelY);
label.line.style.opacity = visible ? "1" : "0";
label.dot.setAttribute("cx", x);
label.dot.setAttribute("cy", y);
label.dot.style.opacity = visible ? "1" : "0";
});
}
let dragging = null;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
dragging = {
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - dragging.x;
const dy = event.clientY - dragging.y;
dragging.x = event.clientX;
dragging.y = event.clientY;
if (dragging.pan) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, new THREE.Vector3(0, 1, 0))
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const worldPerPixel =
(camera.right - camera.left) /
camera.zoom /
renderer.domElement.clientHeight;
view.target
.addScaledVector(right, -dx * worldPerPixel)
.addScaledVector(up, dy * worldPerPixel);
} else {
view.theta -= dx * 0.005;
view.elevation = THREE.MathUtils.clamp(
view.elevation + dy * 0.004,
-0.18,
0.95
);
}
updateCamera();
});
function endDrag(event) {
if (dragging && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
dragging = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.4
);
updateCamera();
},
{ passive: false }
);
function resetView() {
view.theta = initialView.theta;
view.elevation = initialView.elevation;
view.radius = initialView.radius;
view.zoom = initialView.zoom;
view.target.copy(initialView.target);
spindle.rotation.y = 0;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetView);
const spinButton = document.getElementById("spin");
let spinning = false;
spinButton.addEventListener("click", () => {
spinning = !spinning;
spinButton.classList.toggle("active", spinning);
spinButton.textContent = spinning ? "Pause rotation" : "Auto rotate";
});
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetView();
if (event.code === "Space") {
event.preventDefault();
spinButton.click();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
const halfHeight = Math.max(5.65, 6.9 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
leaderSvg.setAttribute("viewBox", `0 0 ${width} ${height}`);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
let previousTime = performance.now();
function animate(time) {
const delta = Math.min(0.05, (time - previousTime) / 1000);
previousTime = time;
if (spinning) {
spindle.rotation.y += delta * 0.18;
}
// Keep the generating profile square to the camera.
profileGroup.quaternion.copy(camera.quaternion);
profileGroup.updateMatrixWorld(true);
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
</script>
</body>
</html>
```