Prompt specification
Build or customize the Three.js 3D scene "End-Mill Footprint and Rounded Pocket Corner" 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: End-Mill Footprint and Rounded Pocket Corner
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/end-mill-footprint-and-rounded-pocket-corner-x2077
Scene Description Prompt:
End-mill footprint and rounded pocket corner. Model a simple cutter footprint inside a rectangular pocket with rounded internal corners. Show how finite tool radius limits the corner geometry in a planar illustration. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (end-mill-footprint-and-rounded-pocket-corner-x2077):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>End Mill Footprint — Rounded Pocket Corner</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: #0c1827;
--panel-2: #122235;
--border: #24364b;
--text: #e7f0f7;
--muted: #91a6ba;
--cyan: #52dcff;
--green: #55e2bb;
--amber: #f5b84b;
--red: #ff6d75;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
display: grid;
grid-template-columns: 310px minmax(0, 1fr);
}
aside {
position: relative;
z-index: 10;
overflow-y: auto;
padding: 24px 22px;
background:
linear-gradient(180deg, rgba(18, 34, 53, 0.96), rgba(9, 20, 34, 0.98));
border-right: 1px solid var(--border);
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.12;
letter-spacing: -0.035em;
}
.intro {
margin: 13px 0 22px;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.card {
margin-top: 13px;
padding: 14px;
background: rgba(18, 34, 53, 0.7);
border: 1px solid var(--border);
border-radius: 10px;
}
.control + .control {
margin-top: 18px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
font-size: 12px;
font-weight: 700;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: ew-resize;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #647b91;
font-size: 10px;
}
.status {
margin-top: 16px;
padding: 11px 12px;
border: 1px solid;
border-radius: 8px;
font-size: 11px;
line-height: 1.45;
}
.status.limited {
color: #ffd2d5;
background: rgba(255, 109, 117, 0.09);
border-color: rgba(255, 109, 117, 0.42);
}
.status.feasible {
color: #c8f8e8;
background: rgba(85, 226, 187, 0.08);
border-color: rgba(85, 226, 187, 0.36);
}
.equation {
color: #dce9f4;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.9;
}
.equation small {
display: block;
margin-top: 8px;
color: var(--muted);
font-family: inherit;
font-size: 10px;
line-height: 1.5;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
button {
min-height: 34px;
padding: 7px 9px;
color: #dce9f4;
background: #172a3e;
border: 1px solid #30465d;
border-radius: 7px;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
}
button:hover {
background: #20364d;
border-color: #4b6883;
}
.legend {
display: grid;
gap: 9px;
font-size: 11px;
color: var(--muted);
}
.legend div {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 22px;
height: 3px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.cyan {
background: var(--cyan);
}
.swatch.amber {
background: var(--amber);
}
.swatch.green {
background: var(--green);
}
.swatch.red {
background: var(--red);
}
.note {
margin: 16px 2px 0;
color: #70879c;
font-size: 10px;
line-height: 1.55;
}
main {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, #102135 0%, #07111e 72%);
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas.grabbing {
cursor: grabbing;
}
.view-badge {
position: absolute;
z-index: 4;
top: 18px;
left: 20px;
padding: 8px 10px;
color: #a8bfd2;
background: rgba(7, 17, 30, 0.75);
border: 1px solid rgba(83, 109, 133, 0.42);
border-radius: 6px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
pointer-events: none;
}
#resetView {
position: absolute;
z-index: 5;
top: 18px;
right: 20px;
background: rgba(12, 28, 45, 0.9);
}
.callout {
position: absolute;
z-index: 6;
min-width: 105px;
padding: 7px 9px;
color: #dce9f4;
background: rgba(7, 17, 30, 0.9);
border: 1px solid #30465d;
border-left: 3px solid var(--cyan);
border-radius: 6px;
font-size: 10px;
line-height: 1.35;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.22);
}
.callout b {
display: block;
color: #fff;
font-size: 10px;
letter-spacing: 0.06em;
}
.callout span {
color: #9fb5c8;
}
.callout.amber {
border-left-color: var(--amber);
}
.callout.green {
border-left-color: var(--green);
}
.callout.red {
border-left-color: var(--red);
}
@media (max-width: 800px) {
html,
body {
height: auto;
overflow: auto;
}
body {
display: flex;
flex-direction: column;
}
aside {
max-height: none;
border-right: 0;
border-bottom: 1px solid var(--border);
}
main {
height: 68vh;
min-height: 520px;
}
.callout.optional {
display: none;
}
}
</style>
</head>
<body>
<aside>
<div class="eyebrow">Planar machining illustration</div>
<h1>End mill footprint<br>and pocket corner</h1>
<p class="intro">
A circular cutter cannot create an arbitrarily sharp internal corner.
Its center must remain one tool radius away from the finished wall.
</p>
<div class="card">
<div class="control">
<div class="control-head">
<label for="toolRadius">Cutter radius</label>
<output id="toolValue"></output>
</div>
<input
id="toolRadius"
type="range"
min="0.35"
max="0.90"
step="0.01"
value="0.58"
>
<div class="range-labels">
<span>3.5 mm</span>
<span>9.0 mm</span>
</div>
</div>
<div class="control">
<div class="control-head">
<label for="designRadius">Desired corner radius</label>
<output id="designValue"></output>
</div>
<input
id="designRadius"
type="range"
min="0.20"
max="1.40"
step="0.01"
value="0.42"
>
<div class="range-labels">
<span>2.0 mm</span>
<span>14.0 mm</span>
</div>
</div>
<div id="status" class="status limited" aria-live="polite"></div>
<div class="buttons">
<button type="button" data-preset="limited">Limited case</button>
<button type="button" data-preset="feasible">Feasible case</button>
</div>
</div>
<div class="card">
<div class="eyebrow">Corner radius rule</div>
<div class="equation">
R<sub>cut</sub> = max(R<sub>design</sub>, R<sub>tool</sub>)<br>
R<sub>path</sub> = max(R<sub>cut</sub> − R<sub>tool</sub>, 0)
<small>
Rpath is the radius of the cutter-center arc.
If Rdesign is smaller than the tool radius, the cutter
overcuts and the smallest practical corner is Rtool.
</small>
</div>
</div>
<div class="card legend">
<div><span class="swatch cyan"></span>Cutter and tangency</div>
<div><span class="swatch amber"></span>Offset cutter-center path</div>
<div><span class="swatch green"></span>Achievable pocket boundary</div>
<div><span class="swatch red"></span>Unreachable target boundary</div>
</div>
<p class="note">
Scale: 1 scene unit = 10 mm. Pocket: 96 × 56 mm.
Drag to pan, use the wheel to zoom, and double-click to reset.
</p>
</aside>
<main id="viewport">
<div class="view-badge">ORTHOGRAPHIC · TOP VIEW</div>
<button id="resetView" type="button">Reset view</button>
<div id="toolCallout" class="callout">
<b>END MILL</b>
<span id="toolDimensions"></span>
</div>
<div id="contactCallout" class="callout">
<b>TANGENCY</b>
<span>cutting edge on wall</span>
</div>
<div id="cornerCallout" class="callout green">
<b>POCKET CORNER</b>
<span id="cornerDimensions"></span>
</div>
<div id="pathCallout" class="callout amber optional">
<b>CENTER PATH</b>
<span>offset by Rtool</span>
</div>
<div id="widthCallout" class="callout optional">
<b>POCKET WIDTH</b>
<span>96 mm</span>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const toolSlider = document.getElementById("toolRadius");
const designSlider = document.getElementById("designRadius");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111e);
const camera = new THREE.OrthographicCamera(-8, 8, 5.5, -5.5, 0.1, 100);
camera.position.set(0, 0, 20);
camera.up.set(0, 1, 0);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive orthographic plan view of a rounded pocket and end mill"
);
viewport.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xb9e8ff, 0x172131, 2.2));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-5, 8, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4bc9ff, 1.4);
rimLight.position.set(7, -5, 8);
scene.add(rimLight);
const worldUnitsToMM = 10;
const STOCK_W = 13.2;
const STOCK_H = 9.0;
const STOCK_DEPTH = 0.28;
const POCKET_W = 9.6;
const POCKET_H = 5.6;
const stockTopMaterial = new THREE.MeshStandardMaterial({
color: 0x2a3c50,
roughness: 0.92,
metalness: 0.08,
flatShading: true
});
const stockSideMaterial = new THREE.MeshStandardMaterial({
color: 0x132337,
roughness: 0.85,
metalness: 0.12,
flatShading: true
});
const pocketFloorMaterial = new THREE.MeshStandardMaterial({
color: 0x0d4050,
roughness: 0.78,
metalness: 0.08,
flatShading: true
});
const toolMaterial = new THREE.MeshStandardMaterial({
color: 0x50d9ff,
roughness: 0.28,
metalness: 0.38,
transparent: true,
opacity: 0.34,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const shankMaterial = new THREE.MeshStandardMaterial({
color: 0xa9bac9,
roughness: 0.3,
metalness: 0.85,
flatShading: true
});
const edgeMaterial = new THREE.MeshBasicMaterial({
color: 0x52dcff
});
const pathMaterial = new THREE.LineDashedMaterial({
color: 0xf5b84b,
dashSize: 0.16,
gapSize: 0.10,
transparent: true,
opacity: 0.95
});
const actualMaterial = new THREE.LineBasicMaterial({
color: 0x55e2bb
});
const targetGoodMaterial = new THREE.LineDashedMaterial({
color: 0x55e2bb,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.72
});
const targetBadMaterial = new THREE.LineDashedMaterial({
color: 0xff6d75,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.95
});
const unreachableMaterial = new THREE.MeshBasicMaterial({
color: 0xff5f6b,
transparent: true,
opacity: 0.23,
side: THREE.DoubleSide,
depthWrite: false
});
const dimensionMaterial = new THREE.LineBasicMaterial({
color: 0x7890a5,
transparent: true,
opacity: 0.7
});
const contactMaterial = new THREE.LineBasicMaterial({
color: 0x52dcff
});
const centerMaterial = new THREE.MeshBasicMaterial({
color: 0xf5b84b,
side: THREE.DoubleSide
});
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xeaf8ff,
side: THREE.DoubleSide
});
const background = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 1
})
);
background.position.z = -0.36;
background.receiveShadow = true;
scene.add(background);
const dynamicGroup = new THREE.Group();
scene.add(dynamicGroup);
const anchors = {};
function roundedRectPoints(width, height, radius, segments = 12, clockwise = false) {
radius = Math.max(
0,
Math.min(radius, Math.min(width, height) * 0.5)
);
const points = [];
if (radius < 1e-6) {
points.push(
new THREE.Vector2(-width / 2, -height / 2),
new THREE.Vector2(width / 2, -height / 2),
new THREE.Vector2(width / 2, height / 2),
new THREE.Vector2(-width / 2, height / 2)
);
} else {
const corners = [
{
cx: width / 2 - radius,
cy: -height / 2 + radius,
a0: -Math.PI / 2,
a1: 0
},
{
cx: width / 2 - radius,
cy: height / 2 - radius,
a0: 0,
a1: Math.PI / 2
},
{
cx: -width / 2 + radius,
cy: height / 2 - radius,
a0: Math.PI / 2,
a1: Math.PI
},
{
cx: -width / 2 + radius,
cy: -height / 2 + radius,
a0: Math.PI,
a1: Math.PI * 1.5
}
];
for (const corner of corners) {
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const angle = THREE.MathUtils.lerp(corner.a0, corner.a1, t);
points.push(
new THREE.Vector2(
corner.cx + Math.cos(angle) * radius,
corner.cy + Math.sin(angle) * radius
)
);
}
}
}
return clockwise ? points.slice().reverse() : points;
}
function shapeFromPoints(points) {
const shape = new THREE.Shape();
shape.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i].x, points[i].y);
}
shape.closePath();
return shape;
}
function lineFrom(points, material) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
if (material.isLineDashedMaterial) {
line.computeLineDistances();
}
return line;
}
function closedLineFrom(points, material, z = 0.3) {
const closed = points.map(
(point) => new THREE.Vector3(point.x, point.y, z)
);
closed.push(closed[0].clone());
return lineFrom(closed, material);
}
function disposeGroup(group) {
for (const child of [...group.children]) {
child.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
});
group.remove(child);
}
}
function cornerDifferencePoints(actualRadius, desiredRadius) {
const targetCenter = new THREE.Vector2(
POCKET_W / 2 - desiredRadius,
POCKET_H / 2 - desiredRadius
);
const actualCenter = new THREE.Vector2(
POCKET_W / 2 - actualRadius,
POCKET_H / 2 - actualRadius
);
const targetArc = [];
const actualArc = [];
const arcSegments = 20;
for (let i = 0; i <= arcSegments; i++) {
const angle = (i / arcSegments) * Math.PI / 2;
targetArc.push(
new THREE.Vector2(
targetCenter.x + Math.cos(angle) * desiredRadius,
targetCenter.y + Math.sin(angle) * desiredRadius
)
);
}
for (let i = arcSegments; i >= 0; i--) {
const angle = (i / arcSegments) * Math.PI / 2;
actualArc.push(
new THREE.Vector2(
actualCenter.x + Math.cos(angle) * actualRadius,
actualCenter.y + Math.sin(angle) * actualRadius
)
);
}
return targetArc.concat(actualArc);
}
function rebuildMachining() {
disposeGroup(dynamicGroup);
const toolRadius = Number(toolSlider.value);
const desiredRadius = Number(designSlider.value);
const actualRadius = Math.max(desiredRadius, toolRadius);
const pathRadius = Math.max(actualRadius - toolRadius, 0);
const isLimited = desiredRadius < toolRadius - 1e-6;
// Stock plate with a real rounded-rectangle hole.
const stockShape = new THREE.Shape();
stockShape.moveTo(-STOCK_W / 2, -STOCK_H / 2);
stockShape.lineTo(STOCK_W / 2, -STOCK_H / 2);
stockShape.lineTo(STOCK_W / 2, STOCK_H / 2);
stockShape.lineTo(-STOCK_W / 2, STOCK_H / 2);
stockShape.closePath();
const holePoints = roundedRectPoints(
POCKET_W,
POCKET_H,
actualRadius,
12,
true
);
const hole = new THREE.Path();
hole.moveTo(holePoints[0].x, holePoints[0].y);
for (let i = 1; i < holePoints.length; i++) {
hole.lineTo(holePoints[i].x, holePoints[i].y);
}
hole.closePath();
stockShape.holes.push(hole);
const stock = new THREE.Mesh(
new THREE.ExtrudeGeometry(stockShape, {
depth: STOCK_DEPTH,
steps: 1,
bevelEnabled: false,
curveSegments: 12
}),
[stockTopMaterial, stockSideMaterial]
);
stock.castShadow = true;
stock.receiveShadow = true;
dynamicGroup.add(stock);
// Pocket floor.
const actualPoints = roundedRectPoints(
POCKET_W,
POCKET_H,
actualRadius,
12,
false
);
const floor = new THREE.Mesh(
new THREE.ShapeGeometry(
shapeFromPoints(actualPoints),
12
),
pocketFloorMaterial
);
floor.position.z = 0.012;
floor.receiveShadow = true;
dynamicGroup.add(floor);
// Outer stock outline.
const outerOutline = [
new THREE.Vector3(-STOCK_W / 2, -STOCK_H / 2, 0.294),
new THREE.Vector3(STOCK_W / 2, -STOCK_H / 2, 0.294),
new THREE.Vector3(STOCK_W / 2, STOCK_H / 2, 0.294),
new THREE.Vector3(-STOCK_W / 2, STOCK_H / 2, 0.294),
new THREE.Vector3(-STOCK_W / 2, -STOCK_H / 2, 0.294)
];
dynamicGroup.add(lineFrom(outerOutline, dimensionMaterial));
// Achievable pocket boundary.
dynamicGroup.add(
closedLineFrom(actualPoints, actualMaterial, 0.296)
);
// Desired boundary, shown separately as a construction line.
const desiredPoints = roundedRectPoints(
POCKET_W,
POCKET_H,
desiredRadius,
12,
false
);
dynamicGroup.add(
closedLineFrom(
desiredPoints,
isLimited ? targetBadMaterial : targetGoodMaterial,
isLimited ? 0.315 : 0.303
)
);
// Shade material that must be overcut when the requested radius
// is tighter than the physical cutter radius.
if (isLimited) {
const difference = cornerDifferencePoints(
actualRadius,
desiredRadius
);
const differenceMesh = new THREE.Mesh(
new THREE.ShapeGeometry(
shapeFromPoints(difference),
12
),
unreachableMaterial
);
differenceMesh.position.z = 0.292;
dynamicGroup.add(differenceMesh);
}
// Full offset path followed by the cutter center.
const pathPoints = roundedRectPoints(
POCKET_W - 2 * toolRadius,
POCKET_H - 2 * toolRadius,
pathRadius,
12,
false
);
dynamicGroup.add(
closedLineFrom(pathPoints, pathMaterial, 0.325)
);
// Geometry of the highlighted upper-right internal corner.
const filletCenter = new THREE.Vector2(
POCKET_W / 2 - actualRadius,
POCKET_H / 2 - actualRadius
);
const radialDirection = new THREE.Vector2(
Math.cos(Math.PI / 4),
Math.sin(Math.PI / 4)
);
const toolCenter = filletCenter
.clone()
.addScaledVector(radialDirection, pathRadius);
const contactPoint = filletCenter
.clone()
.addScaledVector(radialDirection, actualRadius);
const actualArcPoints = [];
for (let i = 0; i <= 20; i++) {
const angle = (i / 20) * Math.PI / 2;
actualArcPoints.push(
new THREE.Vector3(
filletCenter.x + Math.cos(angle) * actualRadius,
filletCenter.y + Math.sin(angle) * actualRadius,
0.33
)
);
}
dynamicGroup.add(lineFrom(actualArcPoints, actualMaterial));
// Cutter footprint on the pocket floor.
const footprint = new THREE.Mesh(
new THREE.CircleGeometry(toolRadius, 24),
new THREE.MeshBasicMaterial({
color: 0x52dcff,
transparent: true,
opacity: 0.10,
side: THREE.DoubleSide,
depthWrite: false
})
);
footprint.position.set(toolCenter.x, toolCenter.y, 0.027);
dynamicGroup.add(footprint);
const footprintRing = [];
for (let i = 0; i <= 24; i++) {
const angle = (i / 24) * Math.PI * 2;
footprintRing.push(
new THREE.Vector3(
toolCenter.x + Math.cos(angle) * toolRadius,
toolCenter.y + Math.sin(angle) * toolRadius,
0.04
)
);
}
dynamicGroup.add(lineFrom(footprintRing, edgeMaterial));
// Low-poly end mill body.
const toolBodyGeometry = new THREE.CylinderGeometry(
1,
1,
1,
24,
1,
false
);
toolBodyGeometry.rotateX(Math.PI / 2);
const toolBody = new THREE.Mesh(
toolBodyGeometry,
toolMaterial
);
const toolBottom = 0.04;
const toolHeight = 1.55;
toolBody.scale.set(
toolRadius,
toolRadius,
toolHeight
);
toolBody.position.set(
toolCenter.x,
toolCenter.y,
toolBottom + toolHeight / 2
);
toolBody.renderOrder = 3;
dynamicGroup.add(toolBody);
// Visible cutter edge rings.
const lowerRing = new THREE.Mesh(
new THREE.TorusGeometry(toolRadius, 0.026, 6, 24),
edgeMaterial
);
lowerRing.position.set(
toolCenter.x,
toolCenter.y,
toolBottom + 0.025
);
dynamicGroup.add(lowerRing);
const upperRing = new THREE.Mesh(
new THREE.TorusGeometry(toolRadius, 0.022, 6, 24),
edgeMaterial
);
upperRing.position.set(
toolCenter.x,
toolCenter.y,
toolBottom + toolHeight
);
dynamicGroup.add(upperRing);
// Cutter shank.
const shankGeometry = new THREE.CylinderGeometry(
1,
1,
1,
12,
1,
false
);
shankGeometry.rotateX(Math.PI / 2);
const shank = new THREE.Mesh(
shankGeometry,
shankMaterial
);
shank.scale.set(0.22, 0.22, 1.2);
shank.position.set(
toolCenter.x,
toolCenter.y,
toolBottom + toolHeight + 0.6
);
dynamicGroup.add(shank);
// Tool radius dimension: cutter center to tangency point.
dynamicGroup.add(
lineFrom(
[
new THREE.Vector3(toolCenter.x, toolCenter.y, 0.345),
new THREE.Vector3(contactPoint.x, contactPoint.y, 0.345)
],
contactMaterial
)
);
// Small contact tick.
const perpendicular = new THREE.Vector2(
-radialDirection.y,
radialDirection.x
);
dynamicGroup.add(
lineFrom(
[
new THREE.Vector3(
contactPoint.x - perpendicular.x * 0.11,
contactPoint.y - perpendicular.y * 0.11,
0.345
),
new THREE.Vector3(
contactPoint.x + perpendicular.x * 0.11,
contactPoint.y + perpendicular.y * 0.11,
0.345
)
],
contactMaterial
)
);
// Markers for the fillet center and current cutter center.
const filletMarker = new THREE.Mesh(
new THREE.RingGeometry(0.055, 0.085, 12),
centerMaterial
);
filletMarker.position.set(
filletCenter.x,
filletCenter.y,
0.34
);
dynamicGroup.add(filletMarker);
const toolMarker = new THREE.Mesh(
new THREE.RingGeometry(0.045, 0.072, 12),
markerMaterial
);
toolMarker.position.set(
toolCenter.x,
toolCenter.y,
0.35
);
dynamicGroup.add(toolMarker);
// Pocket width dimension.
const dimensionY = -POCKET_H / 2 - 0.48;
dynamicGroup.add(
lineFrom(
[
new THREE.Vector3(-POCKET_W / 2, dimensionY, 0.315),
new THREE.Vector3(POCKET_W / 2, dimensionY, 0.315)
],
dimensionMaterial
)
);
for (const x of [-POCKET_W / 2, POCKET_W / 2]) {
dynamicGroup.add(
lineFrom(
[
new THREE.Vector3(x, dimensionY - 0.13, 0.315),
new THREE.Vector3(x, dimensionY + 0.13, 0.315)
],
dimensionMaterial
)
);
}
anchors.tool = toolCenter.clone();
anchors.contact = contactPoint.clone();
anchors.corner = filletCenter.clone();
anchors.path = new THREE.Vector2(
-POCKET_W / 2 + toolRadius * 1.6,
-POCKET_H / 2 + toolRadius
);
anchors.width = new THREE.Vector2(0, dimensionY);
updateUI(
toolRadius,
desiredRadius,
actualRadius,
pathRadius,
isLimited
);
}
function formatMM(value) {
return `${(value * worldUnitsToMM).toFixed(1)} mm`;
}
function updateUI(
toolRadius,
desiredRadius,
actualRadius,
pathRadius,
isLimited
) {
document.getElementById("toolValue").textContent =
formatMM(toolRadius);
document.getElementById("designValue").textContent =
formatMM(desiredRadius);
document.getElementById("toolDimensions").textContent =
`Ø${(toolRadius * worldUnitsToMM * 2).toFixed(1)} mm`;
document.getElementById("cornerDimensions").textContent =
`R${(actualRadius * worldUnitsToMM).toFixed(1)} mm`;
const status = document.getElementById("status");
if (isLimited) {
status.className = "status limited";
status.innerHTML = `
<strong>RADIUS LIMIT</strong><br>
The ${formatMM(desiredRadius)} target is tighter than the
${formatMM(toolRadius)} cutter. The practical pocket radius is
${formatMM(actualRadius)}.
`;
} else {
status.className = "status feasible";
status.innerHTML = `
<strong>FEASIBLE CORNER</strong><br>
The cutter can generate the ${formatMM(desiredRadius)} radius.
Its center-path radius is ${formatMM(pathRadius)}.
`;
}
}
// ------------------------------------------------------------------
// Embedded camera controls: pan and orthographic zoom.
// ------------------------------------------------------------------
let cameraTarget = new THREE.Vector2(0, 0);
let cameraZoom = 1;
let dragState = null;
function updateCamera() {
camera.position.set(
cameraTarget.x,
cameraTarget.y,
20
);
camera.lookAt(cameraTarget.x, cameraTarget.y, 0);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTarget.set(0, 0);
cameraZoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragState = {
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("grabbing");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragState) return;
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
const rect = viewport.getBoundingClientRect();
const worldPerPixel =
(camera.top - camera.bottom) / camera.zoom / rect.height;
cameraTarget.x -= dx * worldPerPixel;
cameraTarget.y += dy * worldPerPixel;
updateCamera();
});
function endDrag(event) {
dragState = null;
renderer.domElement.classList.remove("grabbing");
if (
event.pointerType !== "mouse" &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.001);
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * factor,
0.65,
2.4
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetView").addEventListener("click", resetCamera);
// ------------------------------------------------------------------
// Projected HTML callouts.
// ------------------------------------------------------------------
const callouts = {
tool: {
element: document.getElementById("toolCallout"),
offset: [-78, -48]
},
contact: {
element: document.getElementById("contactCallout"),
offset: [66, -4]
},
corner: {
element: document.getElementById("cornerCallout"),
offset: [-82, 20]
},
path: {
element: document.getElementById("pathCallout"),
offset: [-15, 27]
},
width: {
element: document.getElementById("widthCallout"),
offset: [0, 26]
}
};
function placeCallout(element, point, offsetX, offsetY) {
const projected = new THREE.Vector3(
point.x,
point.y,
0.35
).project(camera);
const rect = viewport.getBoundingClientRect();
const x =
(projected.x * 0.5 + 0.5) * rect.width + offsetX;
const y =
(-projected.y * 0.5 + 0.5) * rect.height + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateCallouts() {
for (const [name, callout] of Object.entries(callouts)) {
if (!anchors[name]) continue;
placeCallout(
callout.element,
anchors[name],
callout.offset[0],
callout.offset[1]
);
}
}
// ------------------------------------------------------------------
// Responsive orthographic framing.
// ------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const requiredWidth = 14.6;
const requiredHeight = 10.5;
const viewHeight = Math.max(
requiredHeight,
requiredWidth / aspect
);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
updateCamera();
}
new ResizeObserver(resize).observe(viewport);
// ------------------------------------------------------------------
// Controls and presets.
// ------------------------------------------------------------------
toolSlider.addEventListener("input", rebuildMachining);
designSlider.addEventListener("input", rebuildMachining);
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
if (button.dataset.preset === "limited") {
toolSlider.value = "0.58";
designSlider.value = "0.42";
} else {
toolSlider.value = "0.58";
designSlider.value = "0.95";
}
rebuildMachining();
});
});
rebuildMachining();
resize();
function animate() {
requestAnimationFrame(animate);
updateCallouts();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```