bambu-printer-mcp 1.1.51 → 1.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -8
- package/dist/ams-mapping.d.ts +19 -0
- package/dist/ams-mapping.js +49 -0
- package/dist/bambu-network-bridge.d.ts +86 -9
- package/dist/bambu-network-bridge.js +284 -4
- package/dist/control-reply.d.ts +21 -0
- package/dist/control-reply.js +44 -0
- package/dist/counterpart/info.js +1 -0
- package/dist/counterpart/route.d.ts +37 -0
- package/dist/counterpart/route.js +78 -0
- package/dist/counterpart/schemas.d.ts +4 -0
- package/dist/counterpart/schemas.js +1 -0
- package/dist/design-guidance.d.ts +26 -0
- package/dist/design-guidance.js +177 -0
- package/dist/fusion-mcp-bridge.d.ts +8 -4
- package/dist/fusion-mcp-bridge.js +36 -10
- package/dist/index.js +202 -45
- package/dist/printers/bambu.d.ts +38 -13
- package/dist/printers/bambu.js +204 -69
- package/dist/printers/camera-sources.d.ts +8 -0
- package/dist/printers/camera-sources.js +66 -0
- package/dist/printers/camera-stream.d.ts +65 -0
- package/dist/printers/camera-stream.js +227 -0
- package/dist/printers/camera-tools.d.ts +192 -0
- package/dist/printers/camera-tools.js +29 -0
- package/dist/printers/camera-wire.d.ts +7 -0
- package/dist/printers/camera-wire.js +40 -0
- package/dist/safety/print-file.d.ts +3 -0
- package/dist/safety/print-file.js +11 -2
- package/dist/safety/printer-state.d.ts +7 -0
- package/dist/safety/printer-state.js +11 -1
- package/dist/slicer/layer-pauses.d.ts +47 -0
- package/dist/slicer/layer-pauses.js +130 -0
- package/dist/stl/stl-manipulator.d.ts +3 -0
- package/dist/stl/stl-manipulator.js +50 -4
- package/package.json +2 -1
- package/src/ams-mapping.ts +52 -0
- package/src/bambu-network-bridge.ts +311 -8
- package/src/control-reply.ts +41 -0
- package/src/counterpart/info.ts +1 -0
- package/src/counterpart/route.ts +91 -0
- package/src/counterpart/schemas.ts +2 -0
- package/src/design-guidance.ts +188 -0
- package/src/fusion-mcp-bridge.ts +30 -10
- package/src/index.ts +195 -49
- package/src/printers/bambu.ts +194 -60
- package/src/printers/camera-sources.ts +53 -0
- package/src/printers/camera-stream.ts +165 -0
- package/src/printers/camera-tools.ts +29 -0
- package/src/printers/camera-wire.ts +39 -0
- package/src/safety/print-file.ts +12 -2
- package/src/safety/printer-state.ts +11 -1
- package/src/slicer/layer-pauses.ts +143 -0
- package/src/stl/stl-manipulator.ts +58 -5
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import JSZip from "jszip";
|
|
3
|
+
/**
|
|
4
|
+
* Pause-at-layer for Bambu-compatible slicer CLIs ("Add pause" in Bambu Studio
|
|
5
|
+
* and OrcaSlicer). The slicer writes the machine's own machine_pause_gcode
|
|
6
|
+
* (M400 U1 on Bambu printers) before the chosen layer, so the printer pauses
|
|
7
|
+
* by itself there and waits for Resume; no remote command is involved.
|
|
8
|
+
*
|
|
9
|
+
* The CLI takes these as --load-custom-gcodes <json> (CustomGCode::Info). It
|
|
10
|
+
* does not apply the pauses a project 3MF already carries in
|
|
11
|
+
* Metadata/custom_gcode_per_print_z.xml, so those are read here and passed the
|
|
12
|
+
* same way. A pause's print_z must be the exact top of its layer: a height
|
|
13
|
+
* between layers lands on the layer below.
|
|
14
|
+
*/
|
|
15
|
+
/** CustomGCode::Type, in the order bbs_3mf.cpp writes it as an integer. */
|
|
16
|
+
const CUSTOM_GCODE_TYPES = ["ColorChange", "PausePrint", "ToolChange", "Template", "Custom", "Unknown"];
|
|
17
|
+
/** 1-based layer numbers, as Bambu Studio's and OrcaSlicer's preview slider count them. */
|
|
18
|
+
export function parsePauseLayers(value) {
|
|
19
|
+
if (value === undefined || value === null || value === "")
|
|
20
|
+
return undefined;
|
|
21
|
+
const raw = Array.isArray(value) ? value : String(value).split(/[\s,;]+/).filter(Boolean);
|
|
22
|
+
const layers = raw.map(entry => Number(entry));
|
|
23
|
+
for (const layer of layers) {
|
|
24
|
+
if (!Number.isInteger(layer) || layer < 2) {
|
|
25
|
+
throw new Error(`pause_at_layers takes whole layer numbers of 2 or more (the printer cannot pause before layer 1), not ${JSON.stringify(value)}.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const unique = [...new Set(layers)].sort((a, b) => a - b);
|
|
29
|
+
return unique.length ? unique : undefined;
|
|
30
|
+
}
|
|
31
|
+
function xmlAttr(tag, name) {
|
|
32
|
+
const match = new RegExp(`\\b${name}="([^"]*)"`).exec(tag);
|
|
33
|
+
return match ? match[1].replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&") : undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The custom G-codes (pauses, colour changes, ...) a project 3MF stores for
|
|
37
|
+
* one plate (1-based), as Bambu Studio and OrcaSlicer save them.
|
|
38
|
+
*/
|
|
39
|
+
export async function readProjectCustomGcodes(threeMfPath, plate = 1) {
|
|
40
|
+
let zip;
|
|
41
|
+
try {
|
|
42
|
+
zip = await JSZip.loadAsync(await fs.promises.readFile(threeMfPath));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const file = zip.file(/^Metadata\/custom_gcode_per_print_z\.xml$/i)[0];
|
|
48
|
+
if (!file)
|
|
49
|
+
return undefined;
|
|
50
|
+
const xml = await file.async("string");
|
|
51
|
+
for (const block of xml.match(/<plate>[\s\S]*?<\/plate>/g) ?? []) {
|
|
52
|
+
const info = /<plate_info\b[^>]*>/.exec(block)?.[0];
|
|
53
|
+
if (Number(info ? xmlAttr(info, "id") : NaN) !== plate)
|
|
54
|
+
continue;
|
|
55
|
+
const gcodes = [];
|
|
56
|
+
for (const tag of block.match(/<layer\b[^>]*>/g) ?? []) {
|
|
57
|
+
const type = CUSTOM_GCODE_TYPES[Number(xmlAttr(tag, "type"))] ?? "Unknown";
|
|
58
|
+
const printZ = Number(xmlAttr(tag, "top_z"));
|
|
59
|
+
if (!Number.isFinite(printZ))
|
|
60
|
+
continue;
|
|
61
|
+
gcodes.push({
|
|
62
|
+
type,
|
|
63
|
+
print_z: printZ,
|
|
64
|
+
color: xmlAttr(tag, "color") ?? "",
|
|
65
|
+
extruder: Number(xmlAttr(tag, "extruder") ?? 1) || 1,
|
|
66
|
+
// Template and Custom keep their G-code text in "extra" (CustomGCode.hpp).
|
|
67
|
+
extra: xmlAttr(tag, "extra") ?? "",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const modeTag = /<mode\b[^>]*>/.exec(block)?.[0];
|
|
71
|
+
return { mode: (modeTag && xmlAttr(modeTag, "value")) || "SingleExtruder", gcodes };
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The plate's G-code text inside a sliced 3MF. */
|
|
76
|
+
export async function readPlateGcode(threeMfPath, plate = 1) {
|
|
77
|
+
const zip = await JSZip.loadAsync(await fs.promises.readFile(threeMfPath));
|
|
78
|
+
const exact = zip.file(`Metadata/plate_${plate}.gcode`);
|
|
79
|
+
const file = exact ?? zip.file(/^Metadata\/plate_\d+\.gcode$/)[0];
|
|
80
|
+
return file ? file.async("string") : undefined;
|
|
81
|
+
}
|
|
82
|
+
/** Each layer's top Z in order, from the slicer's "; Z_HEIGHT:" markers. */
|
|
83
|
+
export function layerTops(gcode) {
|
|
84
|
+
const tops = [];
|
|
85
|
+
for (const match of gcode.matchAll(/^; Z_HEIGHT: ([0-9.]+)\s*$/gm))
|
|
86
|
+
tops.push(Number(match[1]));
|
|
87
|
+
return tops;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The 1-based layers whose block holds a pause: the slicer's "; PAUSE_PRINTING"
|
|
91
|
+
* marker or the machine's pause G-code on its own line.
|
|
92
|
+
*/
|
|
93
|
+
export function pausedLayers(gcode, pauseGcode = "M400 U1") {
|
|
94
|
+
const lines = gcode.split(/\r?\n/);
|
|
95
|
+
const paused = new Set();
|
|
96
|
+
let layer = 0;
|
|
97
|
+
const pauseLine = pauseGcode.trim();
|
|
98
|
+
for (const line of lines) {
|
|
99
|
+
if (line.startsWith("; Z_HEIGHT:")) {
|
|
100
|
+
layer += 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (layer === 0)
|
|
104
|
+
continue;
|
|
105
|
+
const trimmed = line.trim();
|
|
106
|
+
if (trimmed === "; PAUSE_PRINTING" || (pauseLine && trimmed === pauseLine))
|
|
107
|
+
paused.add(layer);
|
|
108
|
+
}
|
|
109
|
+
return [...paused].sort((a, b) => a - b);
|
|
110
|
+
}
|
|
111
|
+
/** The machine_pause_gcode a sliced file was made with (its config block), else Bambu's M400 U1. */
|
|
112
|
+
export function machinePauseGcode(gcode) {
|
|
113
|
+
const match = /^; machine_pause_gcode = (.*)$/m.exec(gcode);
|
|
114
|
+
const value = match?.[1]?.split("\\n")[0]?.trim();
|
|
115
|
+
return value || "M400 U1";
|
|
116
|
+
}
|
|
117
|
+
/** Project custom G-codes plus a pause before each requested layer, at that layer's exact top. */
|
|
118
|
+
export function customGcodesWithPauses(tops, layers, project) {
|
|
119
|
+
const total = tops.length;
|
|
120
|
+
const beyond = layers.filter(layer => layer > total);
|
|
121
|
+
if (beyond.length) {
|
|
122
|
+
throw new Error(`This print has ${total} layers, so it cannot pause before layer ${beyond.join(", ")}.`);
|
|
123
|
+
}
|
|
124
|
+
const pauses = layers.map(layer => ({ type: "PausePrint", print_z: tops[layer - 1], color: "", extruder: 1, extra: "" }));
|
|
125
|
+
const kept = (project?.gcodes ?? []).filter(item => !(item.type === "PausePrint" && pauses.some(p => Math.abs(p.print_z - item.print_z) < 1e-4)));
|
|
126
|
+
return {
|
|
127
|
+
mode: project?.mode || "SingleExtruder",
|
|
128
|
+
gcodes: [...kept, ...pauses].sort((a, b) => a.print_z - b.print_z),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -51,6 +51,8 @@ export interface BambuSliceOptions {
|
|
|
51
51
|
skipModifiedGcodes?: boolean;
|
|
52
52
|
slicePlate?: number;
|
|
53
53
|
processOverrides?: ProcessOverrides;
|
|
54
|
+
pauseAtLayers?: number[];
|
|
55
|
+
customGcodesFile?: string;
|
|
54
56
|
}
|
|
55
57
|
/** Bambu Studio's or OrcaSlicer's own result.json, parsed verbatim. */
|
|
56
58
|
export type SlicerResult = Record<string, unknown>;
|
|
@@ -194,6 +196,7 @@ export declare class STLManipulator extends EventEmitter {
|
|
|
194
196
|
* error_string and plate warnings.
|
|
195
197
|
*/
|
|
196
198
|
sliceSTLWithResult(stlFilePath: string, slicerType: SlicerType, slicerPath: string, slicerProfile?: string, progressCallback?: ProgressCallback, printerPreset?: string, bambuOptions?: BambuSliceOptions): Promise<SliceOutput>;
|
|
199
|
+
private sliceSTLOnce;
|
|
197
200
|
/**
|
|
198
201
|
* Enhanced version of confirmTemperatures with better error handling
|
|
199
202
|
* @param gcodePath Path to the G-code file
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { customGcodesWithPauses, layerTops, machinePauseGcode, pausedLayers, readPlateGcode, readProjectCustomGcodes } from "../slicer/layer-pauses.js";
|
|
1
2
|
import * as THREE from 'three';
|
|
2
3
|
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
|
|
3
4
|
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js';
|
|
@@ -1345,6 +1346,48 @@ export class STLManipulator extends EventEmitter {
|
|
|
1345
1346
|
* error_string and plate warnings.
|
|
1346
1347
|
*/
|
|
1347
1348
|
async sliceSTLWithResult(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, bambuOptions) {
|
|
1349
|
+
const once = (options) => this.sliceSTLOnce(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, options);
|
|
1350
|
+
const layers = bambuOptions?.pauseAtLayers?.length ? bambuOptions.pauseAtLayers : undefined;
|
|
1351
|
+
const cli = slicerType === 'bambustudio' || slicerType === 'orcaslicer' || slicerType === 'orcaslicer-bambulab';
|
|
1352
|
+
const plate = bambuOptions?.slicePlate && bambuOptions.slicePlate > 0 ? bambuOptions.slicePlate : 1;
|
|
1353
|
+
// The CLI drops a project's own pauses and colour changes; carry them over.
|
|
1354
|
+
const project = cli && /\.3mf$/i.test(stlFilePath) ? await readProjectCustomGcodes(stlFilePath, plate) : undefined;
|
|
1355
|
+
if (!layers && !project?.gcodes.length)
|
|
1356
|
+
return once(bambuOptions);
|
|
1357
|
+
if (layers && !cli) {
|
|
1358
|
+
throw new Error(`Pausing at a layer needs the Bambu Studio or OrcaSlicer CLI, not ${slicerType}.`);
|
|
1359
|
+
}
|
|
1360
|
+
const customGcodesFile = path.join(this.tempDir, `custom-gcodes-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
|
|
1361
|
+
try {
|
|
1362
|
+
let tops = [];
|
|
1363
|
+
if (layers) {
|
|
1364
|
+
// A pause sits at its layer's exact top Z; learn the tops from a slice without pauses.
|
|
1365
|
+
if (progressCallback)
|
|
1366
|
+
progressCallback(10, `Finding layer heights for the pause before layer ${layers.join(", ")}`);
|
|
1367
|
+
const plain = await once({ ...bambuOptions, pauseAtLayers: undefined, customGcodesFile: undefined });
|
|
1368
|
+
const gcode = await readPlateGcode(plain.path, plate);
|
|
1369
|
+
if (!gcode)
|
|
1370
|
+
throw new Error('The slicer wrote no plate G-code, so the pause layers cannot be placed.');
|
|
1371
|
+
tops = layerTops(gcode);
|
|
1372
|
+
}
|
|
1373
|
+
const info = layers ? customGcodesWithPauses(tops, layers, project) : project;
|
|
1374
|
+
await fs.promises.writeFile(customGcodesFile, JSON.stringify(info));
|
|
1375
|
+
const result = await once({ ...bambuOptions, customGcodesFile });
|
|
1376
|
+
if (layers) {
|
|
1377
|
+
const gcode = await readPlateGcode(result.path, plate);
|
|
1378
|
+
const placed = gcode ? pausedLayers(gcode, machinePauseGcode(gcode)) : [];
|
|
1379
|
+
const missing = layers.filter(layer => !placed.includes(layer));
|
|
1380
|
+
if (!gcode || missing.length || layerTops(gcode).length !== tops.length) {
|
|
1381
|
+
throw new Error(`The slicer did not place the pause before layer ${(missing.length ? missing : layers).join(", ")}. Nothing was sent to the printer.`);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
return result;
|
|
1385
|
+
}
|
|
1386
|
+
finally {
|
|
1387
|
+
await fs.promises.rm(customGcodesFile, { force: true });
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
async sliceSTLOnce(stlFilePath, slicerType, slicerPath, slicerProfile, progressCallback, printerPreset, bambuOptions) {
|
|
1348
1391
|
const operationId = this.generateOperationId();
|
|
1349
1392
|
this.activeOperations.set(operationId, true);
|
|
1350
1393
|
if (slicerType !== 'orca-slicer-api' && isPathLikeExecutable(slicerPath) && !fs.existsSync(slicerPath)) {
|
|
@@ -1493,8 +1536,8 @@ export class STLManipulator extends EventEmitter {
|
|
|
1493
1536
|
throw new Error("OrcaSlicer's CLI crashes when scale above 1, rotate_x or rotate_y moves a 3MF object below the bed while arranging. " +
|
|
1494
1537
|
"Set arrange to false, or apply the transform in the slicer and export the project.");
|
|
1495
1538
|
}
|
|
1496
|
-
if (
|
|
1497
|
-
throw new Error("Use either repetitions or clone_objects for an STL
|
|
1539
|
+
if (!is3mf && bambuOptions?.repetitions !== undefined && bambuOptions.cloneObjects) {
|
|
1540
|
+
throw new Error("Use either repetitions or clone_objects for an STL, not both.");
|
|
1498
1541
|
}
|
|
1499
1542
|
const inputPath = meshTransform ? await this.transformMeshForCli(stlFilePath, bambuOptions) : stlFilePath;
|
|
1500
1543
|
if (inputPath !== stlFilePath)
|
|
@@ -1534,8 +1577,9 @@ export class STLManipulator extends EventEmitter {
|
|
|
1534
1577
|
if (bambuOptions?.arrange !== undefined)
|
|
1535
1578
|
args.push('--arrange', bambuOptions.arrange ? '1' : '0');
|
|
1536
1579
|
if (bambuOptions?.repetitions !== undefined) {
|
|
1537
|
-
//
|
|
1538
|
-
|
|
1580
|
+
// Both Bambu Studio and Orca count STL copies with --clone-objects.
|
|
1581
|
+
// --repetitions > 1 requires a selected existing plate and rejects --slice 0.
|
|
1582
|
+
if (!is3mf)
|
|
1539
1583
|
args.push('--clone-objects', String(bambuOptions.repetitions));
|
|
1540
1584
|
else
|
|
1541
1585
|
args.push('--repetitions', String(bambuOptions.repetitions));
|
|
@@ -1560,6 +1604,8 @@ export class STLManipulator extends EventEmitter {
|
|
|
1560
1604
|
}
|
|
1561
1605
|
if (bambuOptions?.loadFilamentIds)
|
|
1562
1606
|
args.push('--load-filament-ids', bambuOptions.loadFilamentIds);
|
|
1607
|
+
if (bambuOptions?.customGcodesFile)
|
|
1608
|
+
args.push('--load-custom-gcodes', path.resolve(bambuOptions.customGcodesFile));
|
|
1563
1609
|
args.push(path.resolve(inputPath));
|
|
1564
1610
|
// Override outputFilePath for bambustudio since it produces 3MF, not gcode
|
|
1565
1611
|
outputFilePath = bambuOutputPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bambu-printer-mcp",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.52",
|
|
4
4
|
"description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"jszip": "^3.10.2",
|
|
56
56
|
"mqtt": "^5.16.1",
|
|
57
57
|
"patch-package": "8.0.1",
|
|
58
|
+
"sharp": "0.35.5",
|
|
58
59
|
"three": "^0.173.0",
|
|
59
60
|
"xml2js": "^0.6.2"
|
|
60
61
|
},
|
package/src/ams-mapping.ts
CHANGED
|
@@ -78,3 +78,55 @@ export function bridgeAmsMapping2Entry(value: number, dualNozzle = false): { ams
|
|
|
78
78
|
if (value >= 128) return { ams_id: 128, slot_id: value - 128 };
|
|
79
79
|
return { ams_id: Math.floor(value / 4), slot_id: value % 4 };
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
/** A project filament as the sliced 3MF's Metadata/project_settings.config declares it. */
|
|
83
|
+
export interface ProjectFilament { type: string; filamentId: string; colour: string; nozzle?: number }
|
|
84
|
+
|
|
85
|
+
/** Read every project filament (not just the plate's used ones) from project_settings.config. */
|
|
86
|
+
export function projectFilaments(projectSettings: Record<string, unknown>): ProjectFilament[] {
|
|
87
|
+
const list = (key: string): string[] => Array.isArray(projectSettings[key]) ? (projectSettings[key] as unknown[]).map(String) : [];
|
|
88
|
+
const types = list("filament_type"), ids = list("filament_ids"), colours = list("filament_colour"), nozzles = list("filament_map");
|
|
89
|
+
return types.map((type, index) => ({
|
|
90
|
+
type, filamentId: ids[index] ?? "", colour: colours[index] ?? "",
|
|
91
|
+
...(nozzles[index] !== undefined && Number.isInteger(Number(nozzles[index])) ? { nozzle: Number(nozzles[index]) } : {}),
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The colour the printer reports for an absolute tray value (AMS, AMS-HT or external spool). */
|
|
96
|
+
export function trayColour(rawStatus: any, tray: number): string | undefined {
|
|
97
|
+
const units: any[] = Array.isArray(rawStatus?.ams?.ams) ? rawStatus.ams.ams : [];
|
|
98
|
+
let colour: unknown;
|
|
99
|
+
if (tray === 254 || tray === 255) {
|
|
100
|
+
const slots: any[] = Array.isArray(rawStatus?.vir_slot) ? rawStatus.vir_slot : [];
|
|
101
|
+
colour = slots.find(slot => Number(slot?.id) === tray)?.tray_color ?? (tray === 254 ? rawStatus?.vt_tray?.tray_color : undefined);
|
|
102
|
+
} else if (tray >= 128) {
|
|
103
|
+
colour = units.find(unit => Number(unit?.id) === tray)?.tray?.[0]?.tray_color;
|
|
104
|
+
} else if (tray >= 0) {
|
|
105
|
+
const unit = units.find(candidate => Number(candidate?.id) === Math.floor(tray / 4));
|
|
106
|
+
colour = (Array.isArray(unit?.tray) ? unit.tray : []).find((slot: any) => Number(slot?.id) === tray % 4)?.tray_color;
|
|
107
|
+
}
|
|
108
|
+
return typeof colour === "string" ? colour : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* PrintParams.ams_mapping_info exactly as Bambu Studio and FULU's slicer build it
|
|
113
|
+
* (SelectMachineDialog::get_ams_mapping_result) and send it with every print: one entry per
|
|
114
|
+
* project filament. A mapped filament names its tray, its filament id and type, its colour as
|
|
115
|
+
* #RRGGBBAA and the tray's colour as the printer reports it; an unmapped one carries ams -1.
|
|
116
|
+
* Filament-map nozzle 1 (left) is cloud nozzle 1 and 2 (right) is 0 (CloudTaskNozzleId).
|
|
117
|
+
*/
|
|
118
|
+
export function studioAmsMappingInfo(filaments: ProjectFilament[], mapping: number[], colourOfTray: (tray: number) => string | undefined): Array<Record<string, unknown>> {
|
|
119
|
+
return filaments.map((filament, position) => {
|
|
120
|
+
const tray = mapping[position];
|
|
121
|
+
if (tray === undefined || tray < 0) return { ams: -1, targetColor: "", filamentId: "", filamentType: "" };
|
|
122
|
+
const hex = filament.colour.replace(/^#/, "").toUpperCase();
|
|
123
|
+
return {
|
|
124
|
+
ams: tray,
|
|
125
|
+
targetColor: colourOfTray(tray) ?? "",
|
|
126
|
+
filamentId: filament.filamentId,
|
|
127
|
+
filamentType: filament.type,
|
|
128
|
+
...(filament.nozzle === 1 ? { nozzleId: 1 } : filament.nozzle === 2 ? { nozzleId: 0 } : {}),
|
|
129
|
+
sourceColor: /^[0-9A-F]{6}$/.test(hex) ? `#${hex}FF` : /^[0-9A-F]{8}$/.test(hex) ? `#${hex}` : "",
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|