Prompt specification
Build or customize the Three.js 3D scene "Craft Workshop Matching Turned Parts" 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: Craft Workshop Matching Turned Parts
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/craft-workshop-matching-turned-parts-x2067
Scene Description Prompt:
Craft workshop matching turned parts. Build a small workshop producing several dimensioned wooden knobs from related profiles. Compare generated shapes and keep the manufacturing sequence distinct from decorative rotation. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (craft-workshop-matching-turned-parts-x2067):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Turning Workshop</title>
<style>
:root {
--ink: #26312d;
--muted: #6e7770;
--paper: #f4f0e6;
--panel: #eee8dc;
--line: #d5ccbb;
--accent: #d56838;
--accent-dark: #a94524;
--green: #49685b;
--shadow: 0 12px 30px rgba(41, 46, 38, .12);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d1c2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: minmax(0, 1fr) 380px;
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
background: #d8d1c2;
}
#canvasHost,
#canvasHost canvas {
width: 100%;
height: 100%;
display: block;
}
#canvasHost canvas {
cursor: grab;
touch-action: none;
outline: none;
}
#canvasHost canvas.dragging { cursor: grabbing; }
.scene-header {
position: absolute;
z-index: 4;
top: 24px;
left: 28px;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 3px;
background: var(--accent);
border-radius: 3px;
}
h1 {
margin: 8px 0 7px;
max-width: 390px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 51px);
line-height: .98;
letter-spacing: -.035em;
font-weight: 600;
}
.scene-header p {
margin: 0;
max-width: 385px;
color: #5c665f;
font-size: 13px;
line-height: 1.55;
}
.scene-badge {
position: absolute;
z-index: 5;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(72, 82, 69, .18);
border-radius: 999px;
background: rgba(247, 243, 233, .8);
box-shadow: 0 4px 18px rgba(35, 39, 34, .07);
backdrop-filter: blur(9px);
color: #536058;
font-size: 10px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
.scene-badge i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(213, 104, 56, .14);
}
#partLabels {
position: absolute;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.part-label {
position: absolute;
min-width: 110px;
padding: 7px 9px;
transform: translate(-50%, -100%);
border: 1px solid rgba(62, 68, 61, .17);
border-radius: 8px;
background: rgba(248, 245, 237, .88);
box-shadow: 0 6px 16px rgba(45, 50, 43, .11);
backdrop-filter: blur(6px);
text-align: center;
transition: border-color .2s, background .2s, opacity .2s;
}
.part-label strong {
display: block;
color: #39453f;
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.part-label span {
display: block;
margin-top: 2px;
color: #7b817b;
font-size: 9px;
}
.part-label.active {
border-color: var(--accent);
background: rgba(255, 246, 236, .96);
}
.part-label.active strong { color: var(--accent-dark); }
#processTag {
position: absolute;
z-index: 3;
transform: translate(-50%, -100%);
padding: 9px 12px;
border-radius: 7px;
background: #34443d;
box-shadow: 0 8px 24px rgba(35, 43, 38, .22);
color: #fff8e9;
pointer-events: none;
white-space: nowrap;
}
#processTag::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 19px;
background: #34443d;
}
#processTag b {
display: block;
color: #efb182;
font-size: 9px;
letter-spacing: .16em;
text-transform: uppercase;
}
#processTag span {
display: block;
margin-top: 2px;
font-family: Georgia, serif;
font-size: 15px;
}
.camera-hint {
position: absolute;
z-index: 4;
left: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
color: #5e6a63;
font-size: 11px;
pointer-events: none;
}
.camera-hint kbd {
min-width: 31px;
padding: 5px 7px;
border: 1px solid rgba(63, 72, 64, .18);
border-bottom-width: 2px;
border-radius: 5px;
background: rgba(248, 245, 237, .75);
color: #45534c;
font: 700 10px/1 ui-monospace, monospace;
text-align: center;
}
aside {
position: relative;
z-index: 10;
height: 100%;
overflow-y: auto;
border-left: 1px solid rgba(64, 70, 61, .12);
background: var(--panel);
box-shadow: -10px 0 35px rgba(47, 52, 44, .08);
}
aside::-webkit-scrollbar { width: 8px; }
aside::-webkit-scrollbar-thumb {
border: 2px solid var(--panel);
border-radius: 99px;
background: #b9b09f;
}
.panel-section {
padding: 25px 25px 24px;
border-bottom: 1px solid var(--line);
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.section-head h2 {
margin: 0;
color: #34423b;
font-size: 11px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
.section-head span {
color: #8b8f87;
font-size: 10px;
font-weight: 700;
}
.section-intro {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.profile-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.profile-card {
position: relative;
min-width: 0;
padding: 10px 9px 9px;
border: 1px solid #d2c8b6;
border-radius: 10px;
background: rgba(250, 247, 239, .7);
color: var(--ink);
cursor: pointer;
text-align: left;
transition: transform .16s, border-color .16s, box-shadow .16s, background .16s;
}
.profile-card:hover {
transform: translateY(-2px);
border-color: #b8aa94;
box-shadow: 0 7px 15px rgba(57, 60, 51, .08);
}
.profile-card.active {
border-color: var(--accent);
background: #fff8ed;
box-shadow: 0 0 0 2px rgba(213, 104, 56, .09);
}
.profile-card .swatch {
position: absolute;
top: 9px;
right: 9px;
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--wood);
box-shadow: 0 0 0 2px rgba(255, 255, 255, .8);
}
.profile-card svg {
display: block;
width: 64px;
height: 64px;
margin: 0 auto 3px;
overflow: visible;
}
.profile-card strong {
display: block;
overflow: hidden;
font-family: Georgia, serif;
font-size: 14px;
font-weight: 600;
text-overflow: ellipsis;
white-space: nowrap;
}
.profile-card small {
display: block;
margin-top: 3px;
color: #7b817a;
font-size: 9px;
letter-spacing: .04em;
}
.wide-button {
width: 100%;
margin-top: 12px;
padding: 11px 14px;
border: 0;
border-radius: 8px;
background: var(--green);
color: #fffaf0;
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: .05em;
transition: background .15s, transform .15s;
}
.wide-button:hover {
transform: translateY(-1px);
background: #3b5a4e;
}
.process-steps {
position: relative;
display: grid;
gap: 0;
margin: 18px 0 15px;
padding: 0;
list-style: none;
}
.process-steps::before {
content: "";
position: absolute;
top: 14px;
bottom: 14px;
left: 14px;
width: 1px;
background: #c8bead;
}
.process-step {
position: relative;
display: grid;
grid-template-columns: 29px 1fr auto;
align-items: center;
gap: 10px;
min-height: 41px;
border: 0;
background: transparent;
color: #747b75;
cursor: pointer;
text-align: left;
}
.process-step .number {
position: relative;
z-index: 1;
display: grid;
width: 29px;
height: 29px;
place-items: center;
border: 1px solid #c9c0b0;
border-radius: 50%;
background: var(--panel);
color: #8c918a;
font: 800 9px/1 ui-monospace, monospace;
transition: all .2s;
}
.process-step .name {
font-size: 11px;
font-weight: 750;
}
.process-step .status {
color: #a4a69f;
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: .08em;
}
.process-step.done .number {
border-color: var(--green);
background: var(--green);
color: white;
}
.process-step.done .status {
color: var(--green);
}
.process-step.active .number {
border-color: var(--accent);
background: var(--accent);
color: white;
box-shadow: 0 0 0 4px rgba(213, 104, 56, .12);
}
.process-step.active .name { color: #35443d; }
.process-step.active .status { color: var(--accent-dark); }
#stageDetail {
min-height: 89px;
padding: 14px 15px;
border: 1px solid #d4c9b6;
border-radius: 9px;
background: rgba(249, 246, 237, .66);
}
#stageDetail b {
display: block;
margin-bottom: 5px;
color: #3e4c45;
font-family: Georgia, serif;
font-size: 16px;
font-weight: 600;
}
#stageDetail p {
margin: 0;
color: #737a74;
font-size: 11px;
line-height: 1.55;
}
.process-controls {
display: grid;
grid-template-columns: 1fr 1.4fr 1fr;
gap: 8px;
margin-top: 11px;
}
.process-controls button {
min-height: 37px;
padding: 7px 8px;
border: 1px solid #c8bead;
border-radius: 7px;
background: rgba(250, 247, 239, .7);
color: #4b5751;
cursor: pointer;
font-size: 10px;
font-weight: 800;
transition: all .15s;
}
.process-controls button:hover {
border-color: #9d927f;
background: #fffaf0;
}
.process-controls #nextStep {
border-color: var(--accent);
background: var(--accent);
color: white;
}
.process-controls #autoProcess.active {
border-color: var(--green);
background: var(--green);
color: white;
}
.progress-track {
height: 3px;
margin-top: 13px;
overflow: hidden;
border-radius: 3px;
background: #d8cebd;
}
#progressFill {
width: 0;
height: 100%;
background: var(--accent);
transition: width .35s ease;
}
.presentation-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.presentation-copy strong {
display: block;
color: #3f4d46;
font-size: 12px;
}
.presentation-copy p {
margin: 4px 0 0;
color: #7d827b;
font-size: 10px;
line-height: 1.45;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 45px;
height: 25px;
padding: 0;
border: 0;
border-radius: 99px;
background: #c6bcaa;
cursor: pointer;
transition: background .2s;
}
.switch::after {
content: "";
position: absolute;
top: 4px;
left: 4px;
width: 17px;
height: 17px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(40, 44, 38, .24);
transition: transform .2s;
}
.switch[aria-pressed="true"] { background: var(--green); }
.switch[aria-pressed="true"]::after { transform: translateX(20px); }
.process-note {
display: flex;
gap: 9px;
margin-top: 15px;
padding: 11px 12px;
border-left: 3px solid var(--accent);
border-radius: 0 6px 6px 0;
background: rgba(213, 104, 56, .07);
color: #766d62;
font-size: 10px;
line-height: 1.5;
}
.process-note b {
color: var(--accent-dark);
}
.panel-footer {
padding: 18px 25px 26px;
color: #92958e;
font-size: 9px;
line-height: 1.6;
}
@media (max-width: 980px) {
#app {
grid-template-columns: minmax(0, 1fr) 330px;
}
.panel-section { padding-left: 20px; padding-right: 20px; }
.scene-header { left: 20px; }
.scene-badge { display: none; }
}
@media (max-width: 740px) {
html, body { height: auto; overflow: auto; }
#app { height: auto; display: block; }
#viewport { height: 58vh; min-height: 440px; }
aside { height: auto; overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
.scene-header { top: 18px; left: 18px; }
.scene-header p { max-width: 310px; font-size: 11px; }
h1 { font-size: 34px; }
.camera-hint { left: 18px; bottom: 16px; }
.part-label { min-width: 90px; padding: 5px 7px; }
.part-label span { font-size: 8px; }
}
</style>
</head>
<body>
<main id="app">
<section id="viewport" aria-label="Interactive voxel turning workshop">
<div id="canvasHost"></div>
<header class="scene-header">
<div class="eyebrow">Millhouse · Digital workshop</div>
<h1>Matching turned knobs</h1>
<p>One related family of oak profiles. Compare the generated voxel forms, then run the cutting sequence on the lathe.</p>
</header>
<div class="scene-badge"><i></i> Voxel workbench · 3 mm pitch</div>
<div id="partLabels"></div>
<div id="processTag"><b>Process 01 / 05</b><span>Square the billet</span></div>
<div class="camera-hint">
<kbd>DRAG</kbd>
<span>Orbit</span>
<kbd>SCROLL</kbd>
<span>Zoom</span>
<kbd>2×</kbd>
<span>Reset</span>
</div>
</section>
<aside aria-label="Workshop controls">
<section class="panel-section">
<div class="section-head">
<h2>Profile library</h2>
<span>4 related cuts</span>
</div>
<p class="section-intro">All forms share the same oak stock and voxel pitch. Only the radius table, crown and shoulder change.</p>
<div id="profileList" class="profile-list"></div>
<button id="loadProfile" class="wide-button">Load selected profile on the lathe</button>
</section>
<section class="panel-section">
<div class="section-head">
<h2>Manufacturing sequence</h2>
<span>Material removal</span>
</div>
<p class="section-intro">These ordered operations create the dimensions. The presentation spin never advances a cut.</p>
<ol id="processSteps" class="process-steps"></ol>
<div id="stageDetail" aria-live="polite">
<b>Square the billet</b>
<p>Sawn stock is brought to a repeatable 52 × 52 mm datum before mounting.</p>
</div>
<div class="process-controls">
<button id="prevStep" aria-label="Previous manufacturing step">Back</button>
<button id="nextStep">Next cut →</button>
<button id="autoProcess">Auto run</button>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
</section>
<section class="panel-section">
<div class="section-head">
<h2>Presentation</h2>
<span>View only</span>
</div>
<div class="presentation-row">
<div class="presentation-copy">
<strong>Decorative rotation</strong>
<p>Slowly turn the finished parts on the comparison shelf.</p>
</div>
<button id="spinToggle" class="switch" aria-label="Toggle decorative rotation" aria-pressed="true"></button>
</div>
<div class="process-note">
<span>↻</span>
<div><b>Separate from the process.</b> Decorative rotation changes only the viewing pose. Stock removal, bore depth and finished dimensions occur only in the numbered cutting sequence.</div>
</div>
</section>
<div class="panel-footer">
Nominal dimensions are shown in millimetres. The voxel geometry is a visible manufacturing abstraction, not a smooth CAD render. Drag to orbit, scroll to zoom, and double-click to reset the camera.
</div>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* --------------------------------------------------------------------------
Data: one dimensional family, four related radius tables.
Each profile is [height in mm from the base, radius in mm].
--------------------------------------------------------------------------- */
const profiles = [
{
id: "mushroom",
code: "K-01",
name: "Mushroom",
diameter: 34,
height: 24,
bore: 5,
color: "#c98d4c",
profile: [
[0, 8], [3, 8], [4, 10], [6, 14], [8, 17],
[12, 17], [14, 15], [17, 12], [21, 9], [24, 9]
]
},
{
id: "acorn",
code: "K-02",
name: "Acorn",
diameter: 28,
height: 27,
bore: 5,
color: "#b97538",
profile: [
[0, 8], [2, 9], [4, 11], [7, 14], [10, 14],
[14, 13], [18, 11], [22, 9], [24, 7], [27, 7]
]
},
{
id: "barrel",
code: "K-03",
name: "Barrel",
diameter: 32,
height: 21,
bore: 5,
color: "#d09a5c",
profile: [
[0, 10], [2, 12], [5, 15], [8, 16], [11, 16],
[14, 15], [17, 13], [19, 11], [21, 10]
]
},
{
id: "bun",
code: "K-04",
name: "Low bun",
diameter: 36,
height: 18,
bore: 5,
color: "#c68a47",
profile: [
[0, 12], [2, 14], [4, 17], [7, 18],
[10, 17], [13, 14], [16, 11], [18, 10]
]
}
];
const stages = [
{
short: "Stock",
name: "Square the billet",
detail: "Saw a 52 × 52 mm oak blank and establish a flat datum. The blank is not yet a round turning."
},
{
short: "Rough",
name: "True the cylinder",
detail: "Mount between centres and turn the blank down to approximately Ø44 mm over a 52 mm length."
},
{
short: "Shape",
name: "Cut the selected profile",
detail: "Transfer the chosen radius table. The shared base and shoulder are retained while the crown changes."
},
{
short: "Bore",
name: "Drill the hanger bore",
detail: "Drill a Ø5 mm pilot and bore to 9 mm deep for an M6 hanger bolt, preserving the nominal outside diameter."
},
{
short: "Finish",
name: "Sand and oil",
detail: "Sand to 240 grit, soften the voxel seams visually with oil, and check the profile at Ø ±0.3 mm and H ±0.3 mm."
}
];
const MM = 0.035;
const LATHE = { x: -0.45, y: 1.88, z: -0.38 };
const SHELF_Y = 1.03;
let selectedProfile = profiles[0];
let currentStage = 0;
let spinEnabled = true;
let autoTimer = null;
/* --------------------------------------------------------------------------
Three.js scene
--------------------------------------------------------------------------- */
const host = document.getElementById("canvasHost");
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d8d1c2");
scene.fog = new THREE.Fog("#d8d1c2", 16, 29);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight("#fff6df", "#7e806f", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0cf", 3.4);
sun.position.set(-7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#dbe8ee", 1.05);
fill.position.set(8, 5, -7);
scene.add(fill);
const matCache = new Map();
function material(color, roughness = 0.8, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!matCache.has(key)) {
matCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness,
metalness
}));
}
return matCache.get(key);
}
function box(parent, w, h, d, x, y, z, mat) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
typeof mat === "string" ? material(mat) : mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
for (const child of [...group.children]) {
group.remove(child);
child.traverse(obj => {
if (obj.geometry) obj.geometry.dispose();
});
}
}
/* --------------------------------------------------------------------------
Room and workshop, all built from visible blocks.
--------------------------------------------------------------------------- */
function buildRoom() {
const floorColors = ["#b8a789", "#c2b296", "#b4a58c", "#c9b89a"];
box(scene, 14.6, 0.25, 10.7, 0, -0.16, 0, "#756e5f");
for (let x = 0; x < 14; x++) {
for (let z = 0; z < 10; z++) {
const color = floorColors[(x * 3 + z * 5) % floorColors.length];
box(
scene, 0.96, 0.075, 0.96,
-6.5 + x, -0.035, -4.5 + z,
color
);
}
}
const wallColors = ["#d8ccb5", "#d1c4ad", "#ded3bd"];
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 14; col++) {
const color = wallColors[(row + col * 2) % wallColors.length];
box(
scene, 0.98, 0.72, 0.2,
-6.5 + col, 0.39 + row * 0.73, -5.05,
color
);
}
}
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 10; col++) {
const color = wallColors[(row * 2 + col) % wallColors.length];
box(
scene, 0.2, 0.72, 0.98,
-7.05, 0.39 + row * 0.73, -4.5 + col,
color
);
}
}
// Window and bright sky blocks.
box(scene, 2.35, 1.85, 0.12, -4.4, 3.25, -4.88, "#7896a0");
box(scene, 2.65, 0.16, 0.28, -4.4, 2.28, -4.78, "#8e7659");
box(scene, 2.65, 0.16, 0.28, -4.4, 4.22, -4.78, "#8e7659");
box(scene, 0.16, 2.05, 0.28, -5.68, 3.25, -4.78, "#8e7659");
box(scene, 0.16, 2.05, 0.28, -3.12, 3.25, -4.78, "#8e7659");
box(scene, 0.11, 1.85, 0.2, -4.4, 3.25, -4.7, "#8e7659");
box(scene, 2.3, 0.1, 0.22, -4.4, 3.25, -4.69, "#8e7659");
// Pegboard.
box(scene, 3.35, 2.1, 0.15, 0.2, 3.25, -4.84, "#a88962");
for (let x = 0; x < 9; x++) {
for (let y = 0; y < 5; y++) {
box(
scene, 0.07, 0.07, 0.025,
-1.17 + x * 0.34, 2.5 + y * 0.36, -4.745,
"#725d46"
);
}
}
// Block-built hammer.
box(scene, 0.15, 0.9, 0.16, -0.85, 3.15, -4.55, "#8a5c34");
box(scene, 0.65, 0.23, 0.25, -0.85, 3.57, -4.55, "#69716c");
// Block-built saw.
box(scene, 0.13, 0.8, 0.13, -0.2, 3.05, -4.55, "#6f4c31");
for (let i = 0; i < 6; i++) {
box(scene, 0.18, 0.08, 0.09, -0.11 + i * 0.12, 3.25, -4.55, "#a9aca3");
}
box(scene, 0.1, 0.75, 0.1, 0.62, 3.1, -4.55, "#6f4c31");
// Chisels.
for (let i = 0; i < 5; i++) {
box(scene, 0.12, 0.55, 0.12, 0.98 + i * 0.29, 2.63, -4.55, "#805633");
box(scene, 0.16, 0.46, 0.07, 0.98 + i * 0.29, 2.34, -4.54, "#a8aaa3");
}
// Rear workbench.
box(scene, 4.4, 0.28, 1.45, -3.75, 1.52, -3.65, "#9e7147");
box(scene, 4.15, 0.42, 1.15, -3.75, 1.14, -3.69, "#79563a");
for (const x of [-5.5, -2.0]) {
for (const z of [-4.15, -3.12]) {
box(scene, 0.28, 1.3, 0.28, x, 0.67, z, "#735038");
}
}
// Bench vice.
box(scene, 0.65, 0.35, 0.65, -2.45, 1.82, -3.3, "#5e6866");
box(scene, 0.9, 0.18, 0.18, -2.1, 1.85, -3.3, "#4d5855");
box(scene, 0.14, 0.65, 0.14, -1.74, 1.85, -3.3, "#4d5855");
box(scene, 0.32, 0.32, 0.45, -2.8, 1.82, -3.3, "#6e7774");
// Wooden blank bin.
box(scene, 1.55, 0.72, 1.25, -5.95, 0.38, 1.2, "#8d6440");
box(scene, 1.68, 0.13, 1.36, -5.95, 0.77, 1.2, "#a57a4d");
for (let i = 0; i < 5; i++) {
const b = box(
scene, 0.34, 0.34, 0.8,
-6.4 + (i % 3) * 0.43,
0.96 + Math.floor(i / 3) * 0.28,
1.18,
i % 2 ? "#b88950" : "#c18f55"
);
b.rotation.y = (i % 3 - 1) * 0.1;
}
// Small stool.
box(scene, 0.9, 0.18, 0.82, -4.85, 1.0, 1.75, "#9c7046");
for (const x of [-5.17, -4.53]) {
for (const z of [1.48, 2.02]) {
box(scene, 0.16, 0.9, 0.16, x, 0.47, z, "#735038");
}
}
// Floor offcuts.
box(scene, 0.65, 0.15, 0.34, -5.85, 0.11, 3.25, "#b8874c");
box(scene, 0.48, 0.12, 0.3, -5.2, 0.1, 3.4, "#8e613a");
}
function buildLathe() {
// Bed and rails.
box(scene, 5.9, 0.35, 1.45, -0.45, 1.12, LATHE.z, "#6c5540");
box(scene, 5.55, 0.14, 0.16, -0.45, 1.39, LATHE.z - 0.43, "#a7aaa3");
box(scene, 5.55, 0.14, 0.16, -0.45, 1.39, LATHE.z + 0.43, "#a7aaa3");
// Cabinet and drawers.
box(scene, 2.05, 0.9, 1.4, -1.75, 0.49, LATHE.z, "#52665c");
for (let i = 0; i < 3; i++) {
box(scene, 1.75, 0.18, 0.08, -1.75, 0.25 + i * 0.25, LATHE.z + 0.73, "#43594f");
box(scene, 0.42, 0.07, 0.09, -1.75, 0.25 + i * 0.25, LATHE.z + 0.79, "#b58c52");
}
// Headstock, tailstock and block-built spindle.
box(scene, 1.1, 1.42, 1.25, -3.18, 1.9, LATHE.z, "#596863");
box(scene, 0.74, 0.65, 0.95, -3.12, 2.13, LATHE.z, "#71807a");
box(scene, 0.16, 0.72, 0.88, -3.75, 2.13, LATHE.z, "#384a44");
box(scene, 1.25, 0.24, 0.3, -2.5, 1.9, LATHE.z, "#46544e");
box(scene, 0.9, 1.18, 1.05, 2.15, 1.8, LATHE.z, "#596863");
box(scene, 0.62, 0.55, 0.75, 1.85, 1.91, LATHE.z, "#71807a");
box(scene, 0.12, 0.6, 0.7, 1.43, 1.91, LATHE.z, "#384a44");
// Chuck as a square ring of blocks.
const chuck = new THREE.Group();
scene.add(chuck);
for (const y of [-0.28, 0.28]) {
for (const z of [-0.28, 0.28]) {
box(chuck, 0.34, 0.18, 0.18, 0, y, z, "#46534e");
}
}
// Tool rest and carriage.
box(scene, 1.0, 0.28, 0.95, -0.25, 1.44, LATHE.z, "#4c5d56");
box(scene, 0.24, 0.2, 1.4, -0.25, 1.62, LATHE.z, "#66746d");
box(scene, 0.16, 0.48, 0.18, -0.25, 1.38, LATHE.z + 0.4, "#46564f");
// Switch bank and power lamp.
box(scene, 0.54, 0.58, 0.18, -3.25, 1.22, LATHE.z + 0.7, "#d1b36f");
box(scene, 0.12, 0.12, 0.08, -3.42, 1.34, LATHE.z + 0.82, "#d55c36");
box(scene, 0.12, 0.12, 0.08, -3.18, 1.34, LATHE.z + 0.82, "#668277");
}
function buildDisplayShelf() {
// Two-by-two comparison shelf.
box(scene, 3.95, 0.2, 2.8, 4.12, 0.9, 0.72, "#9b7048");
box(scene, 3.7, 0.26, 2.5, 4.12, 0.73, 0.72, "#77543b");
for (const x of [2.38, 5.86]) {
for (const z of [-0.38, 1.8]) {
box(scene, 0.22, 0.82, 0.22, x, 0.42, z, "#6f4d35");
}
}
box(scene, 4.0, 0.16, 0.15, 4.12, 0.18, 0.72, "#624531");
}
buildRoom();
buildLathe();
buildDisplayShelf();
/* --------------------------------------------------------------------------
Voxel knob generation.
The local axial direction is Y; it can be rotated to the lathe's X axis.
--------------------------------------------------------------------------- */
const voxelMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.76,
metalness: 0
});
function radiusAt(def, height) {
const points = def.profile;
if (height <= points[0][0]) return points[0][1];
for (let i = 1; i < points.length; i++) {
if (height <= points[i][0]) {
const [h0, r0] = points[i - 1];
const [h1, r1] = points[i];
const t = (height - h0) / (h1 - h0);
return THREE.MathUtils.lerp(r0, r1, t);
}
}
return points[points.length - 1][1];
}
function shadeFor(base, layer, x, z) {
const color = new THREE.Color(base);
const hash = ((layer * 17 + Math.abs(x * 13 + z * 7)) % 11) - 5;
color.offsetHSL(hash * 0.0012, hash * 0.004, hash * 0.009);
return color;
}
function createVoxelPart(options) {
const {
def,
axialHeight = def.height,
radiusOverride = null,
cell = 3,
bore = true,
color = def.color,
roughness = 0.76
} = options;
const layers = Math.max(1, Math.round(axialHeight / cell));
const cells = [];
const half = cell * 0.5;
for (let layer = 0; layer < layers; layer++) {
const h = (layer + 0.5) * cell;
const r = radiusOverride === null ? radiusAt(def, h) : radiusOverride;
const n = Math.ceil(r / cell) + 1;
for (let ix = -n; ix <= n; ix++) {
for (let iz = -n; iz <= n; iz++) {
const x = ix * cell;
const z = iz * cell;
const distance = Math.hypot(x, z);
if (distance > r) continue;
// A blind bore is visible only in the upper two voxel layers.
if (bore && layer >= layers - 2 && distance < def.bore * 0.5) {
continue;
}
cells.push({ x, z, layer });
}
}
}
const group = new THREE.Group();
const side = cell * MM * 0.88;
const geometry = new THREE.BoxGeometry(side, side, side);
const localMaterial = roughness === voxelMaterial.roughness
? voxelMaterial
: new THREE.MeshStandardMaterial({ color: "#ffffff", roughness, metalness: 0 });
const mesh = new THREE.InstancedMesh(geometry, localMaterial, cells.length);
mesh.castShadow = true;
mesh.receiveShadow = true;
const dummy = new THREE.Object3D();
cells.forEach((cellData, index) => {
dummy.position.set(
cellData.x * MM,
(cellData.layer + 0.5) * cell * MM,
cellData.z * MM
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, shadeFor(color, cellData.layer, cellData.x, cellData.z));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
group.add(mesh);
if (bore) {
const dark = box(
group,
def.bore * MM * 0.62,
0.055,
def.bore * MM * 0.62,
0,
axialHeight * MM - 0.052,
0,
"#49372a"
);
dark.castShadow = false;
}
return { group, mesh, cellCount: cells.length };
}
function placeHorizontal(group, axialHeight) {
group.rotation.z = -Math.PI / 2;
group.position.set(
LATHE.x - axialHeight * MM * 0.5,
LATHE.y,
LATHE.z
);
}
/* --------------------------------------------------------------------------
Comparison parts.
--------------------------------------------------------------------------- */
const displayParts = [];
const partLabels = [];
const labelHost = document.getElementById("partLabels");
const displayPositions = [
[3.03, -0.02],
[4.87, -0.02],
[3.03, 1.46],
[4.87, 1.46]
];
profiles.forEach((def, index) => {
const part = createVoxelPart({ def });
part.group.position.set(displayPositions[index][0], SHELF_Y, displayPositions[index][1]);
scene.add(part.group);
displayParts.push({ def, ...part });
const label = document.createElement("div");
label.className = "part-label";
label.innerHTML = `<strong>${def.name}</strong><span>Ø${def.diameter} × H${def.height} mm</span>`;
labelHost.appendChild(label);
partLabels.push(label);
});
// Four small orange corner brackets mark the selected output.
const selectionMarker = new THREE.Group();
scene.add(selectionMarker);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(selectionMarker, 0.28, 0.045, 0.075,
sx * 0.53, 0, sz * 0.47, "#d56838");
box(selectionMarker, 0.075, 0.045, 0.28,
sx * 0.65, 0, sz * 0.35, "#d56838");
}
}
/* --------------------------------------------------------------------------
Lathe workpiece and tools.
--------------------------------------------------------------------------- */
const workpieceRoot = new THREE.Group();
const toolRoot = new THREE.Group();
scene.add(workpieceRoot, toolRoot);
let drillTool = null;
let cuttingTool = null;
function createBillet() {
const group = new THREE.Group();
const cell = 13;
const side = cell * MM * 0.94;
for (let x = 0; x < 4; x++) {
for (let y = 0; y < 4; y++) {
for (let z = 0; z < 4; z++) {
const mesh = box(
group, side, side, side,
(x - 1.5) * cell * MM,
(y - 1.5) * cell * MM,
(z - 1.5) * cell * MM,
voxelMaterial
);
mesh.material = voxelMaterial;
mesh.setColorAt
? null
: null;
}
}
}
// Instance coloring is unnecessary for the billet; use warm block variation.
group.children.forEach((mesh, i) => {
const c = new THREE.Color(i % 3 === 0 ? "#bb854c" : i % 3 === 1 ? "#c99758" : "#a9733f");
mesh.material = new THREE.MeshStandardMaterial({ color: c, roughness: 0.83 });
});
group.position.set(LATHE.x, LATHE.y, LATHE.z);
return group;
}
function createHorizontalRough() {
const roughDef = {
height: 54,
profile: [[0, 22], [54, 22]],
bore: 5,
color: "#bd8145"
};
const part = createVoxelPart({
def: roughDef,
axialHeight: 54,
radiusOverride: 22,
cell: 4,
bore: false,
roughness: 0.9
});
placeHorizontal(part.group, 54);
return part.group;
}
function createHorizontalFinished(def) {
const part = createVoxelPart({
def,
bore: true,
roughness: currentStage === 4 ? 0.53 : 0.74
});
placeHorizontal(part.group, def.height);
return part.group;
}
function addCuttingTool() {
const group = new THREE.Group();
box(group, 0.52, 0.12, 0.12, 0, 0, 0, "#414d49");
box(group, 0.18, 0.22, 0.08, 0.22, -0.05, 0, "#a9aaa3");
group.position.set(LATHE.x + 0.2, LATHE.y - 0.43, LATHE.z + 0.1);
toolRoot.add(group);
cuttingTool = group;
}
function addDrillTool() {
const group = new THREE.Group();
// Block-built fluted bit aligned to the X axis.
for (let i = 0; i < 6; i++) {
for (let j = 0; j < 4; j++) {
const angle = (j / 4) * Math.PI * 2 + i * 0.32;
box(
group, 0.16, 0.06, 0.06,
-0.45 + i * 0.16,
Math.cos(angle) * 0.075,
Math.sin(angle) * 0.075,
"#59645f"
);
}
}
box(group, 0.32, 0.23, 0.23, -0.67, 0, 0, "#46534e");
group.position.set(
LATHE.x + selectedProfile.height * MM * 0.5 + 0.6,
LATHE.y,
LATHE.z
);
toolRoot.add(group);
drillTool = group;
}
function rebuildWorkpiece() {
clearGroup(workpieceRoot);
clearGroup(toolRoot);
drillTool = null;
cuttingTool = null;
if (currentStage === 0) {
workpieceRoot.add(createBillet());
} else if (currentStage === 1) {
workpieceRoot.add(createHorizontalRough());
} else {
workpieceRoot.add(createHorizontalFinished(selectedProfile));
}
if (currentStage === 2) addCuttingTool();
if (currentStage === 3) addDrillTool();
}
/* --------------------------------------------------------------------------
UI: profile miniatures, dimensioned cards and manufacturing timeline.
--------------------------------------------------------------------------- */
function profileSVG(def) {
const maxRadius = Math.max(...def.profile.map(p => p[1]));
const left = [];
const right = [];
const count = 26;
for (let i = 0; i <= count; i++) {
const h = (i / count) * def.height;
const r = radiusAt(def, h);
const x = 9 + (i / count) * 46;
const y = 48 - (r / maxRadius) * 33;
left.push(`${x.toFixed(2)},${y.toFixed(2)}`);
right.unshift(`${x.toFixed(2)},${(96 - y).toFixed(2)}`);
}
const path = `M ${left.join(" L ")} L ${right.join(" L ")} Z`;
const boreY = 48 - ((def.bore * 0.5) / maxRadius) * 33;
return `
<svg viewBox="0 0 64 64" role="img" aria-label="${def.name} profile">
<path d="${path}" fill="${def.color}" stroke="#705038" stroke-width="1.2" stroke-linejoin="round"/>
<rect x="28.5" y="${boreY}" width="7" height="7" fill="#58422f"/>
</svg>`;
}
const profileList = document.getElementById("profileList");
const processSteps = document.getElementById("processSteps");
profiles.forEach(def => {
const button = document.createElement("button");
button.className = "profile-card";
button.dataset.id = def.id;
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<i class="swatch" style="--wood:${def.color}"></i>
${profileSVG(def)}
<strong>${def.name}</strong>
<small>${def.code} · Ø${def.diameter} × H${def.height} mm</small>
`;
button.addEventListener("click", () => selectProfile(def.id));
profileList.appendChild(button);
});
stages.forEach((stage, index) => {
const li = document.createElement("li");
li.innerHTML = `
<button class="process-step" data-stage="${index}">
<span class="number">${String(index + 1).padStart(2, "0")}</span>
<span class="name">${stage.name}</span>
<span class="status">Pending</span>
</button>`;
li.querySelector("button").addEventListener("click", () => {
stopAuto();
setStage(index);
});
processSteps.appendChild(li);
});
function selectProfile(id) {
selectedProfile = profiles.find(p => p.id === id);
document.querySelectorAll(".profile-card").forEach(card => {
const active = card.dataset.id === id;
card.classList.toggle("active", active);
card.setAttribute("aria-pressed", String(active));
});
partLabels.forEach((label, index) => {
label.classList.toggle("active", index === profiles.indexOf(selectedProfile));
});
const index = profiles.indexOf(selectedProfile);
const position = displayPositions[index];
selectionMarker.position.set(position[0], SHELF_Y + 0.035, position[1]);
if (currentStage >= 2) rebuildWorkpiece();
}
function updateStageUI() {
const stage = stages[currentStage];
document.getElementById("stageDetail").innerHTML = `
<b>${stage.name}</b>
<p>${stage.detail}</p>`;
document.querySelectorAll(".process-step").forEach((button, index) => {
button.classList.toggle("active", index === currentStage);
button.classList.toggle("done", index < currentStage);
button.querySelector(".status").textContent =
index === currentStage ? "Current" :
index < currentStage ? "Done" : "Pending";
});
document.getElementById("progressFill").style.width = `${currentStage / 4 * 100}%`;
document.getElementById("prevStep").disabled = currentStage === 0;
document.getElementById("nextStep").textContent =
currentStage === stages.length - 1 ? "Complete ✓" : "Next cut →";
const tag = document.getElementById("processTag");
tag.querySelector("b").textContent =
`Process ${String(currentStage + 1).padStart(2, "0")} / 05`;
tag.querySelector("span").textContent = stage.name;
}
function setStage(index) {
currentStage = THREE.MathUtils.clamp(index, 0, stages.length - 1);
rebuildWorkpiece();
updateStageUI();
}
function stopAuto() {
if (autoTimer) clearInterval(autoTimer);
autoTimer = null;
document.getElementById("autoProcess").classList.remove("active");
document.getElementById("autoProcess").textContent = "Auto run";
}
document.getElementById("prevStep").addEventListener("click", () => {
stopAuto();
setStage(currentStage - 1);
});
document.getElementById("nextStep").addEventListener("click", () => {
stopAuto();
if (currentStage < stages.length - 1) setStage(currentStage + 1);
});
document.getElementById("autoProcess").addEventListener("click", () => {
if (autoTimer) {
stopAuto();
return;
}
if (currentStage === stages.length - 1) setStage(0);
const button = document.getElementById("autoProcess");
button.classList.add("active");
button.textContent = "Stop";
autoTimer = setInterval(() => {
if (currentStage >= stages.length - 1) {
stopAuto();
return;
}
setStage(currentStage + 1);
}, 1700);
});
document.getElementById("loadProfile").addEventListener("click", () => {
stopAuto();
setStage(0);
});
document.getElementById("spinToggle").addEventListener("click", event => {
spinEnabled = !spinEnabled;
event.currentTarget.setAttribute("aria-pressed", String(spinEnabled));
});
/* --------------------------------------------------------------------------
Direct camera controls — no addons.
--------------------------------------------------------------------------- */
const orbit = {
target: new THREE.Vector3(0.45, 1.5, -0.1),
radius: 12.3,
azimuth: 0.75,
polar: 1.03
};
function updateCamera() {
const sinPolar = Math.sin(orbit.polar);
camera.position.set(
orbit.target.x + orbit.radius * sinPolar * Math.sin(orbit.azimuth),
orbit.target.y + orbit.radius * Math.cos(orbit.polar),
orbit.target.z + orbit.radius * sinPolar * Math.cos(orbit.azimuth)
);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.azimuth -= dx * 0.006;
orbit.polar = THREE.MathUtils.clamp(orbit.polar - dy * 0.005, 0.35, 1.38);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && 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();
orbit.radius = THREE.MathUtils.clamp(orbit.radius + event.deltaY * 0.009, 7.2, 18);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
orbit.target.set(0.45, 1.5, -0.1);
orbit.radius = 12.3;
orbit.azimuth = 0.75;
orbit.polar = 1.03;
updateCamera();
});
/* --------------------------------------------------------------------------
Labels and animation.
--------------------------------------------------------------------------- */
function projectElement(element, worldPosition, offsetY = 0) {
const p = worldPosition.clone().project(camera);
const visible = p.z > -1 && p.z < 1;
element.style.display = visible ? "block" : "none";
if (visible) {
element.style.left = `${(p.x * 0.5 + 0.5) * viewport.clientWidth}px`;
element.style.top = `${(-p.y * 0.5 + 0.5) * viewport.clientHeight + offsetY}px`;
}
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(viewport);
resize();
selectProfile(profiles[0].id);
updateStageUI();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (spinEnabled) {
displayParts.forEach((part, index) => {
part.group.rotation.y += dt * (0.36 + index * 0.045);
});
}
// The cutting tools move only during their respective manufacturing stages.
if (cuttingTool && currentStage === 2) {
cuttingTool.position.x = LATHE.x + 0.18 + Math.sin(time * 3.2) * 0.12;
}
if (drillTool && currentStage === 3) {
const cycle = (Math.sin(time * 2.25) * 0.5 + 0.5);
drillTool.position.x =
LATHE.x + selectedProfile.height * MM * 0.5 + 0.53 - cycle * 0.38;
drillTool.rotation.x += dt * 5;
}
displayParts.forEach((part, index) => {
projected.set(0, part.def.height * MM + 0.22, 0);
part.group.localToWorld(projected);
projectElement(partLabels[index], projected, 0);
});
projected.set(LATHE.x, LATHE.y + 0.85, LATHE.z);
projectElement(document.getElementById("processTag"), projected, -18);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```