Prompt specification
Build or customize the Three.js 3D scene "Schematic Turning Pass" 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: Schematic Turning Pass
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/schematic-turning-pass-x2066
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts lathe turning of rotationally symmetric parts. Animate a tool marker following a simple profile while a workpiece rotates. Represent material removal with staged meshes and label the process as geometric rather than a machining simulator. Voxel style.
Working Three.js Starter (schematic-turning-pass-x2066):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Lathe — Geometric Profile Study</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(9, 21, 30, 0.82);
--border: rgba(124, 225, 215, 0.2);
--text: #e7f5f3;
--muted: #86a3a5;
--cyan: #59ead5;
--amber: #f3b84d;
--coral: #ff625b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-panel {
position: absolute;
top: 22px;
left: 22px;
width: min(440px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 14px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(22px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.055em;
}
.subtitle {
margin: 9px 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.geometry-badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(255, 98, 91, 0.38);
border-radius: 7px;
background: rgba(255, 98, 91, 0.08);
color: #ffaaa5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.geometry-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 12px var(--coral);
content: "";
}
#status-panel {
position: absolute;
top: 22px;
right: 22px;
width: 278px;
padding: 16px;
border-radius: 14px;
pointer-events: auto;
}
.panel-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
padding: 9px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.055);
font-size: 11px;
}
.status-row:last-of-type {
border-bottom: 0;
}
.status-row span:first-child {
color: var(--muted);
}
.status-row strong {
color: var(--text);
font-size: 11px;
font-weight: 700;
text-align: right;
}
#phase {
color: var(--cyan);
}
.progress-track {
height: 7px;
margin-top: 13px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), #a6ffe8);
box-shadow: 0 0 16px rgba(89, 234, 213, 0.4);
}
.profile-wrap {
margin-top: 16px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.profile-wrap svg {
display: block;
width: 100%;
height: auto;
margin-top: 8px;
overflow: visible;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px 14px;
margin-top: 10px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
#controls {
position: absolute;
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 11px;
padding: 10px;
border-radius: 13px;
transform: translateX(-50%);
pointer-events: auto;
}
button {
min-width: 76px;
padding: 10px 13px;
border: 1px solid rgba(89, 234, 213, 0.32);
border-radius: 8px;
background: rgba(89, 234, 213, 0.09);
color: var(--cyan);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(89, 234, 213, 0.16);
}
button.secondary {
border-color: rgba(255, 255, 255, 0.12);
background: rgba(255, 255, 255, 0.045);
color: var(--muted);
}
.speed-control {
display: flex;
align-items: center;
gap: 9px;
padding: 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 94px;
accent-color: var(--cyan);
}
#help {
position: absolute;
right: 22px;
bottom: 24px;
color: rgba(190, 213, 213, 0.58);
font-size: 9px;
line-height: 1.6;
text-align: right;
text-transform: uppercase;
letter-spacing: 0.08em;
}
@media (max-width: 760px) {
#title-panel {
top: 12px;
left: 12px;
}
#status-panel {
top: auto;
right: 12px;
bottom: 78px;
width: 218px;
padding: 12px;
}
.profile-wrap {
display: none;
}
#controls {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
}
.speed-control {
display: none;
}
#help {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel lathe visualization"></canvas>
<div class="overlay">
<section id="title-panel" class="panel">
<div class="eyebrow">Procedural form study / 01</div>
<h1>Voxel Lathe</h1>
<p class="subtitle">
A rotationally symmetric workpiece is transformed station-by-station
from a voxel stock envelope into a stepped target profile.
</p>
<div class="geometry-badge">Geometric demonstration — not a machining simulator</div>
</section>
<aside id="status-panel" class="panel">
<div class="panel-label">Live construction</div>
<div class="status-row">
<span>Phase</span>
<strong id="phase">RIGHT SHOULDER</strong>
</div>
<div class="status-row">
<span>Cut stations</span>
<strong id="stations">0 / 27</strong>
</div>
<div class="status-row">
<span>Axial travel</span>
<strong id="travel">0%</strong>
</div>
<div class="status-row">
<span>Visual rotation</span>
<strong id="rotation">0 rpm</strong>
</div>
<div class="progress-track">
<div id="progress-fill"></div>
</div>
<div class="profile-wrap">
<div class="panel-label">Target radius / axial position</div>
<svg viewBox="0 0 240 90" role="img" aria-label="Target profile diagram">
<defs>
<linearGradient id="profileFill" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#f3b84d" stop-opacity="0.38"/>
<stop offset="1" stop-color="#f3b84d" stop-opacity="0.03"/>
</linearGradient>
</defs>
<path
d="M 12 78 L 228 78"
fill="none"
stroke="rgba(255,255,255,.13)"
stroke-width="1"
/>
<path
d="M 12 21 L 228 21"
fill="none"
stroke="#68828a"
stroke-width="1"
stroke-dasharray="4 4"
/>
<path id="profile-area" fill="url(#profileFill)" stroke="none"/>
<path id="profile-line" fill="none" stroke="#f3b84d" stroke-width="2.5"/>
<line
id="svg-guide"
x1="228"
x2="228"
y1="12"
y2="80"
stroke="rgba(89,234,213,.35)"
stroke-width="1"
stroke-dasharray="3 3"
/>
<circle id="svg-tool" cx="228" cy="40" r="5" fill="#ff625b"/>
<circle id="svg-tool-ring" cx="228" cy="40" r="9"
fill="none" stroke="#ff625b" stroke-opacity=".45"/>
<text x="12" y="88" fill="#668289" font-size="8">X −</text>
<text x="205" y="88" fill="#668289" font-size="8">X +</text>
</svg>
<div class="legend">
<span><i class="swatch" style="background:#59727c"></i>Stock stage</span>
<span><i class="swatch" style="background:#f3b84d"></i>Target stage</span>
<span><i class="swatch" style="background:#59ead5"></i>Profile path</span>
</div>
</div>
</aside>
<div id="controls" class="panel">
<button id="play" type="button">Pause</button>
<button id="reset" class="secondary" type="button">Reset</button>
<label class="speed-control">
Speed
<input id="speed" type="range" min="0.5" max="2.5" step="0.1" value="1">
<span id="speed-value">1.0×</span>
</label>
</div>
<div id="help">
Drag to orbit · Scroll to zoom<br>
Space to pause · Double-click to reset camera
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 8, 18);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraTarget = new THREE.Vector3(-0.05, 0.12, 0);
const cameraSpherical = new THREE.Spherical(7.25, 1.05, 0.66);
function updateCamera() {
camera.position.copy(cameraTarget).add(
new THREE.Vector3().setFromSpherical(cameraSpherical)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xa9ddff, 0x15212b, 1.65);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1d4, 3.1);
key.position.set(3.5, 6.5, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -4;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 18;
key.shadow.bias = -0.00035;
scene.add(key);
const rim = new THREE.DirectionalLight(0x3fd8d1, 1.9);
rim.position.set(-4, 2.5, -4);
scene.add(rim);
const warm = new THREE.PointLight(0xffa64d, 1.2, 7);
warm.position.set(1.5, 1.6, 2.5);
scene.add(warm);
const axisY = 0.15;
const voxelSize = 0.12;
const voxelGeometry = new THREE.BoxGeometry(
voxelSize * 0.88,
voxelSize * 0.88,
voxelSize * 0.88
);
const profileKnots = [
[-1.56, 0.72],
[-1.32, 0.72],
[-1.20, 0.92],
[-0.72, 0.92],
[-0.60, 0.70],
[ 0.34, 0.70],
[ 0.46, 1.00],
[ 0.78, 1.00],
[ 0.90, 0.76],
[ 1.56, 0.76]
];
function profileRadius(x) {
if (x <= profileKnots[0][0]) return profileKnots[0][1];
if (x >= profileKnots.at(-1)[0]) return profileKnots.at(-1)[1];
for (let i = 0; i < profileKnots.length - 1; i++) {
const [x0, r0] = profileKnots[i];
const [x1, r1] = profileKnots[i + 1];
if (x >= x0 && x <= x1) {
const t = (x - x0) / (x1 - x0);
return THREE.MathUtils.lerp(r0, r1, t);
}
}
return profileKnots.at(-1)[1];
}
// Ground and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(24, 24),
new THREE.MeshStandardMaterial({
color: 0x08131b,
roughness: 0.96,
metalness: 0.03
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.27;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x31505a, 0x152a33);
grid.position.y = -1.255;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// A compact voxel machine base.
const machineMaterial = new THREE.MeshStandardMaterial({
color: 0x253b45,
roughness: 0.66,
metalness: 0.48
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.22, 1.55),
machineMaterial
);
base.position.set(-2.25, -1.13, 0);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const pedestal = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.78, 0.58),
machineMaterial
);
pedestal.position.set(-2.48, -0.7, 0);
pedestal.castShadow = true;
scene.add(pedestal);
// All rotating components live under this group.
const workpieceRoot = new THREE.Group();
workpieceRoot.position.y = axisY;
scene.add(workpieceRoot);
function createVoxelCylinderX({
xStart,
xEnd,
radius,
spacing,
material,
parent,
colorA,
colorB
}) {
const cells = [];
const steps = Math.round((xEnd - xStart) / spacing);
for (let ix = 0; ix <= steps; ix++) {
const x = xStart + ix * spacing;
const limit = Math.ceil(radius / spacing);
for (let gy = -limit; gy <= limit; gy++) {
for (let gz = -limit; gz <= limit; gz++) {
const y = gy * spacing;
const z = gz * spacing;
if (Math.hypot(y, z) <= radius) {
cells.push({ x, y, z });
}
}
}
}
const mesh = new THREE.InstancedMesh(
voxelGeometry,
material,
cells.length
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
cells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const variation = (Math.sin(cell.x * 8 + cell.y * 3 + cell.z) + 1) * 0.5;
color.copy(colorA).lerp(colorB, variation * 0.55);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
parent.add(mesh);
return mesh;
}
// Voxel chuck and spindle.
createVoxelCylinderX({
xStart: -2.68,
xEnd: -1.72,
radius: 1.19,
spacing: 0.125,
material: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.58,
metalness: 0.62
}),
parent: workpieceRoot,
colorA: new THREE.Color(0x253d48),
colorB: new THREE.Color(0x4d6872)
});
const spindle = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 0.46, 0.46),
new THREE.MeshStandardMaterial({
color: 0x304b56,
roughness: 0.5,
metalness: 0.7
})
);
spindle.position.x = -3.12;
spindle.castShadow = true;
workpieceRoot.add(spindle);
const jawMaterial = new THREE.MeshStandardMaterial({
color: 0x81939a,
roughness: 0.45,
metalness: 0.72
});
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2 + Math.PI / 4;
const jaw = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.25, 0.32),
jawMaterial
);
jaw.position.set(
-1.67,
Math.cos(angle) * 0.91,
Math.sin(angle) * 0.91
);
jaw.rotation.x = angle;
jaw.castShadow = true;
workpieceRoot.add(jaw);
}
/*
Each axial station contains two geometric stages:
1. a stock voxel volume outside the target radius;
2. the target-profile voxel volume.
As the tool crosses a station, the stock stage is faded and
contracted while the target stage remains.
*/
const stockRadius = 1.13;
const stations = [];
const targetMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.43,
metalness: 0.55
});
const startX = -1.56;
const endX = 1.56;
const stationStep = 0.12;
const colorTemp = new THREE.Color();
const dummy = new THREE.Object3D();
for (let x = startX; x <= endX + 0.001; x += stationStep) {
const roundedX = Math.round(x * 1000) / 1000;
const targetR = profileRadius(roundedX);
const targetCells = [];
const excessCells = [];
const limit = Math.ceil(stockRadius / voxelSize);
for (let gy = -limit; gy <= limit; gy++) {
for (let gz = -limit; gz <= limit; gz++) {
const y = gy * voxelSize;
const z = gz * voxelSize;
const radial = Math.hypot(y, z);
if (radial <= targetR) {
targetCells.push({ x: roundedX, y, z });
} else if (radial <= stockRadius) {
excessCells.push({ x: roundedX, y, z });
}
}
}
const targetMesh = new THREE.InstancedMesh(
voxelGeometry,
targetMaterial,
targetCells.length
);
targetCells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.updateMatrix();
targetMesh.setMatrixAt(index, dummy.matrix);
const tone = 0.50 + 0.10 * Math.sin(cell.x * 5 + cell.z * 2.1);
colorTemp.setHSL(0.105, 0.78, tone);
targetMesh.setColorAt(index, colorTemp);
});
targetMesh.instanceMatrix.needsUpdate = true;
if (targetMesh.instanceColor) targetMesh.instanceColor.needsUpdate = true;
targetMesh.castShadow = true;
targetMesh.receiveShadow = true;
targetMesh.frustumCulled = false;
workpieceRoot.add(targetMesh);
const excessGroup = new THREE.Group();
const excessMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.75,
metalness: 0.25,
transparent: true,
opacity: 1
});
const excessMesh = new THREE.InstancedMesh(
voxelGeometry,
excessMaterial,
excessCells.length
);
excessCells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.updateMatrix();
excessMesh.setMatrixAt(index, dummy.matrix);
const tone = 0.24 + 0.06 * Math.sin(cell.x * 9 + cell.y * 4);
colorTemp.setHSL(0.55, 0.18, tone);
excessMesh.setColorAt(index, colorTemp);
});
excessMesh.instanceMatrix.needsUpdate = true;
if (excessMesh.instanceColor) excessMesh.instanceColor.needsUpdate = true;
excessMesh.castShadow = true;
excessMesh.receiveShadow = true;
excessMesh.frustumCulled = false;
excessGroup.add(excessMesh);
workpieceRoot.add(excessGroup);
stations.push({
x: roundedX,
targetR,
excessGroup,
excessMaterial,
started: false,
amount: 0
});
}
// Target profile path.
const pathPoints = [];
for (let x = startX; x <= endX + 0.001; x += 0.025) {
pathPoints.push(
new THREE.Vector3(x, axisY + profileRadius(x), 0)
);
}
const pathGeometry = new THREE.BufferGeometry().setFromPoints(pathPoints);
const pathMaterial = new THREE.LineBasicMaterial({
color: 0x59ead5,
transparent: true,
opacity: 0.9
});
const pathLine = new THREE.Line(pathGeometry, pathMaterial);
scene.add(pathLine);
const stockGuideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(startX, axisY + stockRadius, 0),
new THREE.Vector3(endX, axisY + stockRadius, 0)
]);
const stockGuide = new THREE.Line(
stockGuideGeometry,
new THREE.LineDashedMaterial({
color: 0x78929a,
dashSize: 0.08,
gapSize: 0.06,
transparent: true,
opacity: 0.5
})
);
stockGuide.computeLineDistances();
scene.add(stockGuide);
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-3.6, axisY, 0),
new THREE.Vector3(2.1, axisY, 0)
]);
const axisLine = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x4f727c,
dashSize: 0.1,
gapSize: 0.08,
transparent: true,
opacity: 0.38
})
);
axisLine.computeLineDistances();
scene.add(axisLine);
// Small voxel ticks make the profile path legible.
const tickGeometry = new THREE.BoxGeometry(0.035, 0.035, 0.035);
const tickMaterial = new THREE.MeshBasicMaterial({ color: 0x59ead5 });
for (let x = startX; x <= endX + 0.001; x += 0.24) {
const tick = new THREE.Mesh(tickGeometry, tickMaterial);
tick.position.set(x, axisY + profileRadius(x) + 0.035, 0);
scene.add(tick);
}
// Voxel tool marker.
const toolGroup = new THREE.Group();
const toolRed = new THREE.MeshStandardMaterial({
color: 0xff625b,
emissive: 0x8a110d,
emissiveIntensity: 0.65,
roughness: 0.38,
metalness: 0.2
});
const toolDark = new THREE.MeshStandardMaterial({
color: 0x9eaaa9,
roughness: 0.5,
metalness: 0.65
});
const tip = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.16, 0.16),
toolRed
);
toolGroup.add(tip);
const neck = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.2, 0.18),
toolDark
);
neck.position.y = 0.17;
toolGroup.add(neck);
const shoulder = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.12, 0.19),
toolDark
);
shoulder.position.y = 0.32;
toolGroup.add(shoulder);
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.35, 0.14),
toolRed
);
stem.position.y = 0.53;
toolGroup.add(stem);
const toolLight = new THREE.PointLight(0xff625b, 1.3, 2.2);
toolLight.position.y = 0.18;
toolGroup.add(toolLight);
scene.add(toolGroup);
function makeLabel(text, color = "#59ead5") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = "rgba(7,16,24,.86)";
ctx.fillRect(8, 20, 496, 84);
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.strokeRect(8, 20, 496, 84);
ctx.font = "bold 40px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.fillText(text, 256, 63);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.85, 0.46, 1);
sprite.renderOrder = 20;
return sprite;
}
const profileLabel = makeLabel("TARGET PROFILE", "#59ead5");
profileLabel.position.set(-0.45, 1.94, 0);
scene.add(profileLabel);
const toolLabel = makeLabel("TOOL", "#ff625b");
toolLabel.position.set(0, 0.91, 0.02);
toolLabel.scale.set(0.72, 0.18, 1);
toolGroup.add(toolLabel);
// Pooled voxel chips: a geometric indication of removed stock.
const MAX_CHIPS = 256;
const chipGeometry = new THREE.BoxGeometry(0.075, 0.075, 0.075);
const chipMaterial = new THREE.MeshStandardMaterial({
color: 0x78919a,
roughness: 0.8,
metalness: 0.2
});
const chipMesh = new THREE.InstancedMesh(
chipGeometry,
chipMaterial,
MAX_CHIPS
);
chipMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
chipMesh.frustumCulled = false;
scene.add(chipMesh);
const chipPool = Array.from({ length: MAX_CHIPS }, () => ({
active: false,
age: 0,
life: 1.5,
position: new THREE.Vector3(),
velocity: new THREE.Vector3(),
spin: new THREE.Vector3(),
rotation: new THREE.Euler()
}));
const chipDummy = new THREE.Object3D();
function spawnChips(station) {
const count = 6 + Math.floor(Math.random() * 4);
for (let i = 0; i < count; i++) {
const chip = chipPool.find(item => !item.active);
if (!chip) break;
const angle = Math.random() * Math.PI * 2;
const radialY = Math.cos(angle);
const radialZ = Math.sin(angle);
const radius = stockRadius + 0.015;
chip.active = true;
chip.age = 0;
chip.life = 1.1 + Math.random() * 0.8;
chip.position.set(
station.x + (Math.random() - 0.5) * 0.08,
axisY + radialY * radius,
radialZ * radius
);
const tangentY = -radialZ;
const tangentZ = radialY;
chip.velocity.set(
(Math.random() - 0.5) * 0.26,
radialY * 0.18 + tangentY * (0.45 + Math.random() * 0.32),
radialZ * 0.18 + tangentZ * (0.45 + Math.random() * 0.32)
);
chip.spin.set(
Math.random() * 4,
Math.random() * 4,
Math.random() * 4
);
chip.rotation.set(0, 0, 0);
}
}
function updateChips(dt) {
for (let i = 0; i < MAX_CHIPS; i++) {
const chip = chipPool[i];
if (chip.active) {
chip.age += dt;
if (chip.age >= chip.life) {
chip.active = false;
} else {
chip.velocity.y -= 1.35 * dt;
chip.position.addScaledVector(chip.velocity, dt);
chip.rotation.x += chip.spin.x * dt;
chip.rotation.y += chip.spin.y * dt;
chip.rotation.z += chip.spin.z * dt;
const scale = Math.max(0.001, 1 - chip.age / chip.life);
chipDummy.position.copy(chip.position);
chipDummy.rotation.copy(chip.rotation);
chipDummy.scale.setScalar(scale);
}
}
if (!chip.active) {
chipDummy.position.set(0, -100, 0);
chipDummy.rotation.set(0, 0, 0);
chipDummy.scale.setScalar(0.001);
}
chipDummy.updateMatrix();
chipMesh.setMatrixAt(i, chipDummy.matrix);
}
chipMesh.instanceMatrix.needsUpdate = true;
}
// Animation state.
const state = {
playing: true,
speed: 1,
progress: 0,
toolX: 1.68,
rotation: 0,
elapsed: 0
};
const TOOL_START = 1.68;
const TOOL_END = -1.68;
const DURATION = 22;
function updateToolPosition() {
const r = profileRadius(state.toolX);
toolGroup.position.set(
state.toolX,
axisY + r + 0.055,
0.17
);
}
function resetScene() {
state.progress = 0;
state.toolX = TOOL_START;
state.rotation = 0;
for (const station of stations) {
station.started = false;
station.amount = 0;
station.excessGroup.visible = true;
station.excessGroup.scale.set(1, 1, 1);
station.excessMaterial.opacity = 1;
station.excessMaterial.depthWrite = true;
}
for (const chip of chipPool) {
chip.active = false;
}
updateToolPosition();
updateChips(0);
updateUI();
}
function updateStations(dt) {
for (const station of stations) {
if (!station.started && state.toolX <= station.x + 0.015) {
station.started = true;
spawnChips(station);
}
if (station.started && station.amount < 1) {
station.amount = Math.min(
1,
station.amount + dt * state.speed * 5.4
);
const a = station.amount;
station.excessGroup.scale.set(
1 - a * 0.18,
1 - a * 0.94,
1 - a * 0.94
);
station.excessMaterial.opacity = 1 - a;
station.excessMaterial.depthWrite = a < 0.08;
if (a >= 0.995) {
station.excessGroup.visible = false;
}
}
}
}
// SVG profile diagram.
const svgNS = "http://www.w3.org/2000/svg";
const profileLine = document.querySelector("#profile-line");
const profileArea = document.querySelector("#profile-area");
const svgTool = document.querySelector("#svg-tool");
const svgToolRing = document.querySelector("#svg-tool-ring");
const svgGuide = document.querySelector("#svg-guide");
const svgPoint = ([x, r]) => {
const sx = 12 + ((x + 1.56) / 3.12) * 216;
const sy = 78 - r * 50;
return [sx, sy];
};
const profileSvgPoints = profileKnots.map(svgPoint);
const profilePath = profileSvgPoints
.map(([x, y], index) => `${index === 0 ? "M" : "L"} ${x} ${y}`)
.join(" ");
profileLine.setAttribute("d", profilePath);
profileArea.setAttribute(
"d",
`${profilePath} L ${profileSvgPoints.at(-1)[0]} 78 L ${profileSvgPoints[0][0]} 78 Z`
);
const phaseLabel = document.querySelector("#phase");
const stationsLabel = document.querySelector("#stations");
const travelLabel = document.querySelector("#travel");
const rotationLabel = document.querySelector("#rotation");
const progressFill = document.querySelector("#progress-fill");
const playButton = document.querySelector("#play");
function phaseFor(x) {
if (x > 1.1) return "RIGHT SHOULDER";
if (x > 0.48) return "OUTER RING";
if (x > -0.48) return "CENTRAL NECK";
if (x > -1.08) return "LEFT RING";
return "LEFT SHOULDER";
}
function updateUI() {
const completed = stations.filter(s => s.amount >= 0.995).length;
const percent = Math.round(state.progress * 100);
const rpm = Math.round(state.rotation * 60 / (Math.PI * 2));
phaseLabel.textContent = phaseFor(state.toolX);
stationsLabel.textContent = `${completed} / ${stations.length}`;
travelLabel.textContent = `${percent}%`;
rotationLabel.textContent = `${rpm} rpm`;
progressFill.style.width = `${percent}%`;
const [sx, sy] = svgPoint([
THREE.MathUtils.clamp(state.toolX, -1.56, 1.56),
profileRadius(state.toolX)
]);
svgTool.setAttribute("cx", sx);
svgTool.setAttribute("cy", sy);
svgToolRing.setAttribute("cx", sx);
svgToolRing.setAttribute("cy", sy);
svgGuide.setAttribute("x1", sx);
svgGuide.setAttribute("x2", sx);
}
// UI controls.
const speedInput = document.querySelector("#speed");
const speedValue = document.querySelector("#speed-value");
speedInput.addEventListener("input", () => {
state.speed = Number(speedInput.value);
speedValue.textContent = `${state.speed.toFixed(1)}×`;
});
playButton.addEventListener("click", () => {
if (state.progress >= 1) {
resetScene();
state.playing = true;
} else {
state.playing = !state.playing;
}
playButton.textContent = state.playing ? "Pause" : "Play";
});
document.querySelector("#reset").addEventListener("click", () => {
resetScene();
state.playing = true;
playButton.textContent = "Pause";
});
window.addEventListener("keydown", event => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
playButton.click();
}
});
// Direct camera controls — no OrbitControls or addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraSpherical.theta -= dx * 0.006;
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi - dy * 0.005,
0.34,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraSpherical.radius = THREE.MathUtils.clamp(
cameraSpherical.radius * Math.exp(event.deltaY * 0.001),
4.6,
11
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => {
cameraSpherical.set(7.25, 1.05, 0.66);
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
// Main loop.
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
state.elapsed += dt;
if (state.playing) {
if (state.progress < 1) {
state.progress = Math.min(
1,
state.progress + (dt * state.speed) / DURATION
);
state.toolX = THREE.MathUtils.lerp(
TOOL_START,
TOOL_END,
state.progress
);
state.rotation += dt * state.speed * 3.8;
updateToolPosition();
updateStations(dt);
if (state.progress >= 1) {
state.playing = false;
playButton.textContent = "Replay";
}
}
}
workpieceRoot.rotation.x = state.rotation;
const pulse = 1 + Math.sin(state.elapsed * 7) * 0.035;
toolGroup.scale.setScalar(pulse);
pathMaterial.opacity = 0.78 + Math.sin(state.elapsed * 3) * 0.12;
updateChips(dt);
updateUI();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateToolPosition();
updateChips(0);
updateUI();
animate();
</script>
</body>
</html>
```