// Deterministic generator for the 13 physical-case structure GLBs. // Every movable joint is a Group named after its slot key and carries // userData.linuxcncJoint so the analyzer, the manager and the runtime can // bind it without name heuristics. Motion itself is never computed here: // the models only encode zero pose, hierarchy and joint axes. import { mkdir, writeFile } from 'node:fs/promises'; import { createHash } from 'node:crypto'; import * as THREE from '../web/react/node_modules/three/build/three.module.js'; import { GLTFExporter } from '../web/react/node_modules/three/examples/jsm/exporters/GLTFExporter.js'; globalThis.FileReader = class { readAsArrayBuffer(blob) { blob.arrayBuffer().then((value) => { this.result = value; this.onloadend?.(); }); } readAsDataURL(blob) { blob.arrayBuffer().then((value) => { this.result = `data:${blob.type};base64,${Buffer.from(value).toString('base64')}`; this.onloadend?.(); }); } }; const out = new URL('../web/react/public/machine-cases/physical/', import.meta.url); await mkdir(out, { recursive: true }); const colors = { base: 0x334a55, steel: 0x9fb3bb, blue: 0x167f9a, orange: 0xe39a35, dark: 0x17242b, white: 0xd8e3e6, joint: 0xc56d26, black: 0x11181c, gold: 0xd7b45a }; const material = (name, metalness = .35, roughness = .38) => new THREE.MeshStandardMaterial({ color: colors[name] ?? colors.steel, metalness, roughness }); const group = (parent, name, position = [0, 0, 0]) => { const g = new THREE.Group(); g.name = name; g.position.fromArray(position); parent.add(g); return g; }; const box = (parent, name, size, position, mat = 'steel') => { const m = new THREE.Mesh(new THREE.BoxGeometry(...size), material(mat)); m.name = name; m.position.fromArray(position); parent.add(m); return m; }; const cyl = (parent, name, radius, length, position, mat = 'steel', axis = 'z') => { const m = new THREE.Mesh(new THREE.CylinderGeometry(radius, radius, length, 32), material(mat)); m.name = name; m.position.fromArray(position); if (axis === 'x') m.rotation.z = Math.PI / 2; if (axis === 'y') m.rotation.x = Math.PI / 2; parent.add(m); return m; }; const bar = (parent, name, a, b, radius = 10, mat = 'steel') => { const va = new THREE.Vector3(...a), vb = new THREE.Vector3(...b), delta = vb.clone().sub(va); const m = new THREE.Mesh(new THREE.CylinderGeometry(radius, radius, delta.length(), 24), material(mat)); m.name = name; m.position.copy(va.clone().add(vb).multiplyScalar(.5)); m.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), delta.normalize()); parent.add(m); return m; }; // One movable slot. dir/sign are the joint axis in the parent frame; the model // keeps its zero pose so the runtime can evaluate absolute transforms. function joint(parent, caseId, index, key, axis, kind, dir, sign = 1, position = [0, 0, 0], source = 'kinematics') { const g = group(parent, key.toLowerCase().replace(/[^a-z0-9]+/g, '_'), position); g.userData.linuxcncNodeId = `${caseId}:${key}`; g.userData.linuxcncJoint = { index, key, axis, type: kind, unit: kind === 'revolute' ? 'deg' : 'mm', direction: dir, sign, drive: 'joint', source }; return g; } function strut(parent, caseId, index) { const g = group(parent, `strut_${index + 1}`); g.userData.linuxcncNodeId = `${caseId}:J${index}`; g.userData.linuxcncJoint = { index, key: `J${index}`, axis: null, type: 'strut', unit: 'mm', direction: 'z', sign: 1, drive: 'joint', source: 'kinematics' }; return g; } function setup(id, coordinates, kinematics, referenceStatus) { const scene = new THREE.Scene(); scene.name = `physical_${id}`; scene.userData.linuxcncPhysicalStructure = { schema: 'linuxcnc.physical-machine/1', caseId: id, coordinates, kinematics, referenceStatus, units: 'mm/deg', gltfUnit: 'm', generated: true, generator: 'scripts/generate_physical_case_glbs.mjs', license: 'CC0-1.0 procedural design reference', parts: [] }; return scene; } function bed(scene, width = 900, depth = 700) { const base = group(scene, 'base'); box(base, 'bed_casting', [width, depth, 100], [0, 0, -50], 'base'); box(base, 'chip_tray', [width * .95, depth * .88, 18], [0, 0, 12], 'dark'); return base; } // Vertical mill body. The slot list is explicit so every case can describe its // own joint order without a second, implicit convention inside the builder. function linearMill(scene, { id, slots }) { const base = bed(scene); box(base, 'column', [140, 420, 520], [0, 130, 300], 'base'); const nodes = new Map(); let parent = base; // Slots tagged `under` are built on their named branch below, not in the Z chain. for (const slot of slots.filter((item) => item.branch !== 'table' && !item.under)) { const g = joint(parent, id, slot.index, slot.key, slot.axis, slot.kind, slot.dir, slot.sign ?? 1, slot.position ?? [0, 0, 0], slot.source); nodes.set(slot.index, g); if (slot.kind === 'prismatic') box(g, `${slot.key.toLowerCase()}_body`, slot.size ?? [240, 200, 50], [0, 0, 0], slot.mat ?? 'blue'); else cyl(g, `${slot.key.toLowerCase()}_bearings`, 64, 380, [0, 0, 0], 'joint', slot.dir); parent = g; } const tool = group(parent, 'tool', [0, 0, -90]); cyl(tool, 'spindle', 52, 180, [0, 0, 40], 'dark'); cyl(tool, 'tool_holder', 18, 90, [0, 0, -110], 'joint'); cyl(tool, 'tool', 8, 90, [0, 0, -200], 'gold'); const wSlot = slots.find((item) => item.under === 'tool'); if (wSlot) { const w = joint(tool, id, wSlot.index, wSlot.key, wSlot.axis, wSlot.kind, wSlot.dir, wSlot.sign ?? 1, [0, 0, 0], wSlot.source); nodes.set(wSlot.index, w); cyl(w, 'w_tool_direction', 16, 120, [0, 0, -60], 'gold'); } const tableSlots = slots.filter((item) => item.branch === 'table'); let tableParent = base; for (const [order, slot] of tableSlots.entries()) { const g = joint(tableParent, id, slot.index, slot.key, slot.axis, slot.kind, slot.dir, slot.sign ?? 1, slot.position ?? [0, 0, 55 - order * 5], slot.source); nodes.set(slot.index, g); if (slot.kind === 'revolute') cyl(g, `${slot.key.toLowerCase()}_bearings`, 100, 380, [0, 0, 0], 'joint', slot.dir === 'x' ? 'x' : slot.dir === 'y' ? 'y' : 'z'); else box(g, `${slot.key.toLowerCase()}_slide`, [200, 160, 60], [0, 0, 0], 'orange'); tableParent = g; } const last = tableSlots.length ? nodes.get(tableSlots.at(-1).index) : base; cyl(last, 'work_platter', 180, 28, [0, 0, 60], 'steel'); box(last, 'workholding', [190, 110, 28], [0, 0, 88], 'orange'); const gantry = slots.find((item) => item.under === 'base'); if (gantry) { const g = joint(base, id, gantry.index, gantry.key, gantry.axis, gantry.kind, gantry.dir, gantry.sign ?? 1, gantry.position ?? [0, 220, 80], gantry.source); nodes.set(gantry.index, g); box(g, 'y_right_gantry_drive', [120, 160, 120], [0, 0, 0], 'orange'); } scene.userData.linuxcncPhysicalStructure.parts = ['base', ...slots.map((slot) => slot.key.toLowerCase()), 'tool']; return scene; } function bridge(scene, id) { const base = bed(scene, 1800, 1000); box(base, 'foundation', [1900, 1100, 60], [0, 0, -80], 'dark'); box(base, 'left_column', [160, 360, 900], [-700, 100, 450], 'base'); box(base, 'right_column', [160, 360, 900], [700, 100, 450], 'base'); box(base, 'bridge_beam', [1500, 240, 160], [0, 100, 820], 'blue'); const x = joint(base, id, 0, 'X', 'X', 'prismatic', 'x'); box(x, 'moving_table', [1450, 720, 75], [0, 0, 50], 'steel'); const yTwin = joint(base, id, 6, 'Y#2', 'Y', 'prismatic', 'y', 1, [700, 0, 500], 'duplicate'); box(yTwin, 'y_right_gantry', [90, 120, 120], [0, 0, 0], 'orange'); box(base, 'y_left_servo', [90, 120, 120], [-700, 0, 500], 'orange'); const y = joint(base, id, 1, 'Y', 'Y', 'prismatic', 'y', 1, [0, 0, 500]); box(y, 'bridge_carriage', [360, 300, 140], [0, 0, 220], 'blue'); const z = joint(y, id, 2, 'Z', 'Z', 'prismatic', 'z'); box(z, 'ram', [180, 180, 430], [0, 0, 0], 'steel'); const b = joint(z, id, 3, 'B', 'B', 'revolute', 'y', -1, [0, 0, -220]); cyl(b, 'b_axis_bearings', 92, 260, [0, 0, 0], 'joint', 'y'); const c = joint(b, id, 4, 'C', 'C', 'revolute', 'z', 1, [0, 0, -160]); cyl(c, 'c_spindle_axis', 54, 220, [0, 0, -60], 'dark'); const tool = group(c, 'tool', [0, 0, -170]); const w = joint(tool, id, 5, 'W', 'W', 'prismatic', 'z', 1, [0, 0, 0]); cyl(w, 'w_tool_direction', 16, 120, [0, 0, -60], 'gold'); scene.userData.linuxcncPhysicalStructure.parts = ['base', 'x_slide', 'y_slide', 'z_slide', 'b_head', 'c_head', 'tool', 'y_right_gantry', 'w_tool_direction']; return scene; } function max5(scene, id) { const base = bed(scene); box(base, 'column', [160, 420, 480], [0, 150, 300], 'base'); const x = joint(base, id, 0, 'X', 'X', 'prismatic', 'x'); box(x, 'x_table', [520, 360, 55], [0, 0, 0], 'blue'); const y = joint(x, id, 1, 'Y', 'Y', 'prismatic', 'y', 1, [0, 0, 80]); box(y, 'y_saddle', [260, 220, 50], [0, 0, -25], 'steel'); const z = joint(y, id, 2, 'Z', 'Z', 'prismatic', 'z', 1, [0, 0, 170]); box(z, 'z_ram', [135, 145, 260], [0, 0, 60], 'blue'); const b = joint(z, id, 3, 'B', 'B', 'revolute', 'y', -1, [0, 0, -80]); cyl(b, 'b_head', 70, 180, [0, 0, -60], 'dark', 'y'); const tool = group(b, 'tool', [0, 0, -140]); cyl(tool, 'tool', 10, 110, [0, 0, -55], 'gold'); const c = joint(base, id, 4, 'C', 'C', 'revolute', 'z', 1, [0, 0, 60]); cyl(c, 'c_horizontal_table', 200, 40, [0, 0, 0], 'steel'); box(c, 'workholding', [190, 110, 28], [0, 0, 34], 'orange'); joint(base, id, 5, 'J5', null, 'prismatic', 'z', 1, [0, 0, 0], 'passive'); scene.userData.linuxcncPhysicalStructure.parts = ['base', 'x_slide', 'y_saddle', 'z_slide', 'b_head', 'tool', 'c_horizontal_table']; return scene; } function parallel(scene, id, count) { const base = bed(scene, 1100, 850); box(base, 'base_plate', [900, 700, 40], [0, 0, 20], 'steel'); const platform = group(base, 'moving_platform', [0, 0, 600]); for (let i = 0; i < count; i += 1) { const angle = i * Math.PI * 2 / count; const anchor = [420 * Math.cos(angle), 420 * Math.sin(angle), 20]; const s = strut(base, id, i); s.position.fromArray(anchor); const lower = group(s, `strut_${i + 1}_lower`); bar(lower, 'rod', [0, 0, 0], [0, 0, 540], 18, 'steel'); const upper = group(s, `strut_${i + 1}_upper`, [0, 0, 540]); cyl(upper, 'rod', 11, 60, [0, 0, 0], 'joint', 'z'); s.userData.linuxcncStrut = { index: i, lower: lower.name, upper: upper.name, baseAnchorMm: anchor, platformAnchorMm: [170 * Math.cos(angle + .3), 170 * Math.sin(angle + .3), 560], zeroLengthMm: 540 }; } box(platform, 'platform_plate', [300, 300, 45], [0, 0, 0], 'blue'); cyl(platform, 'spindle', 50, 180, [0, 0, -110], 'dark'); cyl(platform, 'tool', 16, 120, [0, 0, -250], 'gold'); scene.userData.linuxcncPhysicalStructure.parts = ['base', ...Array.from({ length: count }, (_, i) => `strut_${i + 1}`), 'moving_platform', 'spindle', 'tool']; return scene; } function robot(scene, id, count) { const base = bed(scene, 650, 650); cyl(base, 'base_turntable', 150, 70, [0, 0, 30], 'dark'); const j1 = joint(base, id, 0, 'J0', null, 'revolute', 'z', 1, [0, 0, 60]); const j2 = joint(j1, id, 1, 'J1', null, 'revolute', 'y', 1, [0, 0, 200]); box(j2, 'upper_arm', [100, 100, 260], [0, 0, 125], 'blue'); const j3 = joint(j2, id, 2, 'J2', null, 'revolute', 'y', 1, [0, 0, 260]); box(j3, 'forearm', [82, 82, 260], [0, 0, 130], 'steel'); const j4 = joint(j3, id, 3, 'J3', null, 'revolute', 'z', 1, [0, 0, 260]); cyl(j4, 'wrist_1', 55, 110, [0, 0, 55], 'joint', 'z'); const j5 = joint(j4, id, 4, 'J4', null, 'revolute', 'y', 1, [0, 0, 110]); cyl(j5, 'wrist_2', 48, 95, [0, 0, 48], 'joint', 'y'); let tip = j5; if (count > 5) { const j6 = joint(j5, id, 5, 'J5', null, 'revolute', 'z', 1, [0, 0, 96]); cyl(j6, 'wrist_3', 40, 90, [0, 0, 45], 'joint', 'z'); tip = j6; } const tool = group(tip, 'tool', [0, 0, 90]); cyl(tool, 'tool', 14, 120, [0, 0, 60], 'gold'); scene.userData.linuxcncPhysicalStructure.parts = ['base', ...Array.from({ length: count }, (_, i) => `J${i}`), 'tool']; return scene; } const specs = [ ['xyzac-trt', () => linearMill(setup('xyzac-trt', 'XYZAC', 'xyzac-trt-kins', 'real-reference'), { id: 'xyzac-trt', slots: [ { index: 0, key: 'X', axis: 'X', kind: 'prismatic', dir: 'x', size: [520, 360, 55] }, { index: 1, key: 'Y', axis: 'Y', kind: 'prismatic', dir: 'y', position: [0, 0, 80], size: [260, 220, 50], mat: 'steel' }, { index: 2, key: 'Z', axis: 'Z', kind: 'prismatic', dir: 'z', position: [0, 0, 170], size: [135, 145, 290] }, { index: 3, key: 'A', axis: 'A', kind: 'revolute', dir: 'x', branch: 'table', position: [0, 0, 55] }, { index: 4, key: 'C', axis: 'C', kind: 'revolute', dir: 'z', branch: 'table', position: [0, 0, 50] }, ] })], ['xyzbc-trt', () => linearMill(setup('xyzbc-trt', 'XYZBC', 'xyzbc-trt-kins', 'real-reference'), { id: 'xyzbc-trt', slots: [ { index: 0, key: 'X', axis: 'X', kind: 'prismatic', dir: 'x', size: [520, 360, 55] }, { index: 1, key: 'Y', axis: 'Y', kind: 'prismatic', dir: 'y', position: [0, 0, 80], size: [260, 220, 50], mat: 'steel' }, { index: 2, key: 'Z', axis: 'Z', kind: 'prismatic', dir: 'z', position: [0, 0, 170], size: [135, 145, 290] }, { index: 3, key: 'B', axis: 'B', kind: 'revolute', dir: 'y', branch: 'table', position: [0, 0, 55] }, { index: 4, key: 'C', axis: 'C', kind: 'revolute', dir: 'z', branch: 'table', position: [0, 0, 50] }, ] })], ['xyzab-tdr', () => linearMill(setup('xyzab-tdr', 'XYZAB', 'xyzab_tdr_kins', 'design-reference'), { id: 'xyzab-tdr', slots: [ { index: 0, key: 'X', axis: 'X', kind: 'prismatic', dir: 'x', size: [520, 360, 55] }, { index: 1, key: 'Y', axis: 'Y', kind: 'prismatic', dir: 'y', position: [0, 0, 80], size: [260, 220, 50], mat: 'steel' }, { index: 2, key: 'Z', axis: 'Z', kind: 'prismatic', dir: 'z', position: [0, 0, 170], size: [135, 145, 290] }, { index: 3, key: 'A', axis: 'A', kind: 'revolute', dir: 'x', branch: 'table', position: [0, 0, 55] }, { index: 4, key: 'B', axis: 'B', kind: 'revolute', dir: 'y', branch: 'table', position: [0, 0, 50] }, ] })], ['bridge-mill-5axiskins', () => bridge(setup('bridge-mill-5axiskins', 'XYZBCWY', '5axiskins', 'real-reference'), 'bridge-mill-5axiskins')], ['max5-maxkins', () => max5(setup('max5-maxkins', 'XYZBC', 'maxkins', 'design-reference'), 'max5-maxkins')], ['hexapod-genhexkins', () => parallel(setup('hexapod-genhexkins', 'XYZABC', 'genhexkins', 'real-reference'), 'hexapod-genhexkins', 6)], ['pentapod-pentakins', () => parallel(setup('pentapod-pentakins', 'XYZAB', 'pentakins', 'real-reference'), 'pentapod-pentakins', 5)], ['puma-pumakins', () => robot(setup('puma-pumakins', 'XYZABC', 'pumakins', 'real-reference'), 'puma-pumakins', 6)], ['puma-genserkins', () => robot(setup('puma-genserkins', 'XYZABC', 'genserkins', 'real-reference'), 'puma-genserkins', 6)], ['trivkins-xyzab', () => linearMill(setup('trivkins-xyzab', 'XYZAB', 'trivkins', 'design-reference'), { id: 'trivkins-xyzab', slots: [ { index: 0, key: 'X', axis: 'X', kind: 'prismatic', dir: 'x', size: [520, 360, 55] }, { index: 1, key: 'Y', axis: 'Y', kind: 'prismatic', dir: 'y', position: [0, 0, 80], size: [260, 220, 50], mat: 'steel' }, { index: 2, key: 'Z', axis: 'Z', kind: 'prismatic', dir: 'z', position: [0, 0, 170], size: [135, 145, 290] }, { index: 3, key: 'A', axis: 'A', kind: 'revolute', dir: 'x', branch: 'table', position: [0, 0, 55] }, { index: 4, key: 'B', axis: 'B', kind: 'revolute', dir: 'y', branch: 'table', position: [0, 0, 50] }, ] })], ['trivkins-xyzcw', () => linearMill(setup('trivkins-xyzcw', 'XYZCW', 'trivkins', 'design-reference'), { id: 'trivkins-xyzcw', slots: [ { index: 0, key: 'X', axis: 'X', kind: 'prismatic', dir: 'x', size: [520, 360, 55] }, { index: 1, key: 'Y', axis: 'Y', kind: 'prismatic', dir: 'y', position: [0, 0, 80], size: [260, 220, 50], mat: 'steel' }, { index: 2, key: 'Z', axis: 'Z', kind: 'prismatic', dir: 'z', position: [0, 0, 170], size: [135, 145, 290] }, { index: 3, key: 'C', axis: 'C', kind: 'revolute', dir: 'z', branch: 'table', position: [0, 0, 55] }, { index: 4, key: 'W', axis: 'W', kind: 'prismatic', dir: 'z', under: 'tool', position: [0, 0, 0] }, ] })], ['trivkins-xyzya', () => linearMill(setup('trivkins-xyzya', 'XYZYA', 'trivkins', 'design-reference'), { id: 'trivkins-xyzya', slots: [ { index: 0, key: 'X', axis: 'X', kind: 'prismatic', dir: 'x', size: [520, 360, 55] }, { index: 1, key: 'Y', axis: 'Y', kind: 'prismatic', dir: 'y', position: [0, 0, 80], size: [260, 220, 50], mat: 'steel' }, { index: 2, key: 'Z', axis: 'Z', kind: 'prismatic', dir: 'z', position: [0, 0, 170], size: [135, 145, 290] }, { index: 3, key: 'Y#2', axis: 'Y', kind: 'prismatic', dir: 'y', under: 'base', position: [-420, 0, 80], source: 'duplicate' }, { index: 4, key: 'A', axis: 'A', kind: 'revolute', dir: 'x', branch: 'table', position: [0, 0, 55] }, ] })], ['scorbot-kins', () => robot(setup('scorbot-kins', 'XYZAB', 'scorbot-kins', 'real-reference'), 'scorbot-kins', 5)], ]; const manifest = { schema: 'linuxcnc.physical-machine-glb/1', license: 'CC0-1.0 procedural design reference', generator: 'scripts/generate_physical_case_glbs.mjs', cases: [] }; for (const [id, make] of specs) { const scene = make(); const exportScene = new THREE.Scene(); exportScene.name = scene.name; exportScene.userData = scene.userData; const machineRoot = group(exportScene, 'machine_root'); while (scene.children.length) machineRoot.add(scene.children[0]); machineRoot.scale.setScalar(0.001); exportScene.updateMatrixWorld(true); const bytes = await new GLTFExporter().parseAsync(exportScene, { binary: true, trs: true, onlyVisible: false }); const buffer = Buffer.from(bytes); await writeFile(new URL(`${id}.glb`, out), buffer); const structure = scene.userData.linuxcncPhysicalStructure; const joints = []; machineRoot.traverse((node) => { if (node.userData.linuxcncJoint) joints.push({ ...node.userData.linuxcncJoint, node: node.name, nodeId: node.userData.linuxcncNodeId }); }); manifest.cases.push({ id, coordinates: structure.coordinates, kinematics: structure.kinematics, filename: `${id}.glb`, bytes: buffer.length, sha256: createHash('sha256').update(buffer).digest('hex'), referenceStatus: structure.referenceStatus, parts: structure.parts, joints: joints.sort((a, b) => a.index - b.index) }); exportScene.traverse((o) => o.geometry?.dispose()); } await writeFile(new URL('manifest.json', out), `${JSON.stringify(manifest, null, 2)}\n`); await writeFile(new URL('LICENSE.txt', out), 'Procedural design-reference assets for linuxcncWebWASM. CC0-1.0.\nNo manufacturer affiliation or dimensional calibration is implied.\n'); console.log(JSON.stringify({ schema: 'physical-case-glb-generation.v1', cases: manifest.cases.length, joints: manifest.cases.reduce((sum, c) => sum + c.joints.length, 0) }));