bambu-printer-mcp 1.1.96 → 1.1.98

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.
Files changed (49) hide show
  1. package/dist/cad/contracts.js +7 -5
  2. package/dist/cad-engine.js +1 -0
  3. package/dist/counterpart/info.js +1 -0
  4. package/dist/counterpart/make-3mf.d.ts +1 -0
  5. package/dist/counterpart/make-3mf.js +37 -5
  6. package/dist/counterpart/model-plates.d.ts +2 -0
  7. package/dist/counterpart/model-plates.js +3 -0
  8. package/dist/counterpart/part-meshes.d.ts +114 -0
  9. package/dist/counterpart/part-meshes.js +323 -0
  10. package/dist/counterpart/plate-filaments.d.ts +3 -0
  11. package/dist/counterpart/plate-filaments.js +31 -10
  12. package/dist/counterpart/remote.js +1 -0
  13. package/dist/counterpart/schemas.d.ts +10 -0
  14. package/dist/counterpart/schemas.js +2 -0
  15. package/dist/design-app-setup.d.ts +9 -0
  16. package/dist/design-app-setup.js +5 -2
  17. package/dist/design-guidance.d.ts +3 -3
  18. package/dist/design-guidance.js +11 -4
  19. package/dist/index.js +82 -6
  20. package/dist/refusal.d.ts +31 -1
  21. package/dist/refusal.js +30 -1
  22. package/dist/slicer/filament-feed.d.ts +61 -0
  23. package/dist/slicer/filament-feed.js +99 -0
  24. package/dist/slicer/floating-regions.d.ts +54 -0
  25. package/dist/slicer/floating-regions.js +198 -0
  26. package/dist/slicer/profile-flatten.js +4 -0
  27. package/dist/tool-annotations.js +2 -0
  28. package/package.json +2 -2
  29. package/src/cad/contracts.ts +7 -5
  30. package/src/cad/project3mf.py +9 -4
  31. package/src/cad/scan_measure.py +207 -0
  32. package/src/cad/scan_touchup.py +4 -1
  33. package/src/cad/worker.py +2 -1
  34. package/src/cad-engine.ts +1 -0
  35. package/src/counterpart/info.ts +1 -0
  36. package/src/counterpart/make-3mf.ts +33 -7
  37. package/src/counterpart/model-plates.ts +4 -0
  38. package/src/counterpart/part-meshes.ts +304 -0
  39. package/src/counterpart/plate-filaments.ts +25 -9
  40. package/src/counterpart/remote.ts +1 -0
  41. package/src/counterpart/schemas.ts +4 -0
  42. package/src/design-app-setup.ts +7 -2
  43. package/src/design-guidance.ts +11 -4
  44. package/src/index.ts +80 -7
  45. package/src/refusal.ts +37 -1
  46. package/src/slicer/filament-feed.ts +116 -0
  47. package/src/slicer/floating-regions.ts +187 -0
  48. package/src/slicer/profile-flatten.ts +3 -0
  49. package/src/tool-annotations.ts +2 -0
@@ -0,0 +1,323 @@
1
+ /**
2
+ * counterpart_part_meshes (counterpart/1, scan-to-make #691 and #845): one STL per printable part of any 3MF, in its
3
+ * filament's colour, so a client can draw a multi-colour design part by part, or show a designer's published 3MF in
4
+ * AR, without reading 3MF itself.
5
+ *
6
+ * Plates, parts and filaments come from list_3mf_plates (model-plates.ts), so both tools agree on what a part is and
7
+ * which filament it prints with. Each part is written in the 3MF's build frame, in millimetres: its component
8
+ * transforms and its build item's transform applied, and the root model's unit converted, so the parts line up when drawn
9
+ * together. Only bounded model text is read; nothing in the file is run. Shared by bambu-printer-mcp and
10
+ * mcp-3D-printer-server.
11
+ */
12
+ import fs from "node:fs/promises";
13
+ import path from "node:path";
14
+ import { readSafe3mfArchive } from "../safety/archive.js";
15
+ import { listModelPlates } from "./model-plates.js";
16
+ import { COUNTERPART_CONTRACT } from "./schemas.js";
17
+ const MAX_MODEL_BYTES = 64 * 1024 * 1024;
18
+ const MAX_TOTAL_BYTES = 256 * 1024 * 1024;
19
+ const MAX_DEPTH = 8;
20
+ /** All the STLs one call writes, together: about 200 MB of binary STL. Parts beyond it are listed in skipped. */
21
+ export const MAX_TOTAL_TRIANGLES = 4000000;
22
+ const ROOT = "3D/3dmodel.model";
23
+ const UNITS = { micron: 0.001, millimeter: 1, centimeter: 10, inch: 25.4, foot: 304.8, meter: 1000 };
24
+ export class PartMeshesError extends Error {
25
+ }
26
+ function fail(message) { throw new PartMeshesError(message); }
27
+ /** A 3MF transform ("m00 m01 m02 m10 m11 m12 m20 m21 m22 m30 m31 m32", row vectors) as 12 numbers; identity when absent. */
28
+ function matrix(value) {
29
+ const identity = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
30
+ if (!value)
31
+ return identity;
32
+ const numbers = value.trim().split(/\s+/).map(Number);
33
+ return numbers.length === 12 && numbers.every(Number.isFinite) ? numbers : fail(`A transform in the 3MF is malformed: "${value.slice(0, 80)}".`);
34
+ }
35
+ /** First a, then b (p' = (p a) b). */
36
+ function compose(a, b) {
37
+ const out = new Array(12);
38
+ for (let r = 0; r < 4; r++)
39
+ for (let c = 0; c < 3; c++)
40
+ out[r * 3 + c] = a[r * 3] * b[c] + a[r * 3 + 1] * b[3 + c] + a[r * 3 + 2] * b[6 + c] + (r === 3 ? b[9 + c] : 0);
41
+ return out;
42
+ }
43
+ /** The model files, read once each within the byte budgets. */
44
+ function modelReader(zip) {
45
+ const files = new Map();
46
+ let total = 0;
47
+ return async (name) => {
48
+ const known = files.get(name);
49
+ if (known !== undefined)
50
+ return known;
51
+ const file = zip.file(name);
52
+ let result;
53
+ if (!file)
54
+ result = `the model part ${name} is missing from the file`;
55
+ else {
56
+ const bytes = await file.async("nodebuffer");
57
+ total += bytes.length;
58
+ if (bytes.length > MAX_MODEL_BYTES)
59
+ result = `its model part ${name} is larger than ${MAX_MODEL_BYTES / 1024 / 1024} MiB`;
60
+ else if (total > MAX_TOTAL_BYTES)
61
+ result = `the 3MF's model parts are larger than ${MAX_TOTAL_BYTES / 1024 / 1024} MiB in all`;
62
+ else {
63
+ const text = bytes.toString("utf8");
64
+ const unit = /<(?:\w+:)?model\b[^>]*\bunit="(\w+)"/.exec(text)?.[1] ?? "millimeter";
65
+ const objects = new Map();
66
+ // An <object .../> closes itself: its (empty) body never runs on into the next object's.
67
+ for (const object of text.matchAll(/<(?:\w+:)?object\b([^>]*?)(?:\/>|>([\s\S]*?)<\/(?:\w+:)?object>)/g)) {
68
+ const id = /\bid="(\d+)"/.exec(object[1])?.[1];
69
+ if (id)
70
+ objects.set(id, object[2] ?? "");
71
+ }
72
+ // Only the root model's unit counts (3MF core spec); a model part's own is read and ignored.
73
+ result = { scale: UNITS[unit] ?? (name === ROOT ? fail(`The 3MF's unit "${unit}" is not one the 3MF standard defines.`) : 1), objects };
74
+ }
75
+ }
76
+ files.set(name, result);
77
+ return result;
78
+ };
79
+ }
80
+ /** Each mesh object parsed once, however many copies and components place it. */
81
+ const parsed = new WeakMap();
82
+ function parseMesh(model, file, id, mesh) {
83
+ let cache = parsed.get(model);
84
+ if (!cache)
85
+ parsed.set(model, cache = new Map());
86
+ const known = cache.get(id);
87
+ if (known)
88
+ return known;
89
+ let result;
90
+ const vertices = [];
91
+ for (const v of mesh.matchAll(/<(?:\w+:)?vertex\b([^>]*)\/?>/g)) {
92
+ const x = Number(/\bx="([^"]+)"/.exec(v[1])?.[1]), y = Number(/\by="([^"]+)"/.exec(v[1])?.[1]), z = Number(/\bz="([^"]+)"/.exec(v[1])?.[1]);
93
+ vertices.push(x, y, z);
94
+ }
95
+ const count = vertices.length / 3;
96
+ const corners = [];
97
+ if (!vertices.every(Number.isFinite))
98
+ result = `a vertex of object ${id} in ${file} is not a number`;
99
+ else {
100
+ result = { vertices: Float64Array.from(vertices), corners: new Uint32Array() };
101
+ for (const tri of mesh.matchAll(/<(?:\w+:)?triangle\b([^>]*)\/?>/g)) {
102
+ const c = ["v1", "v2", "v3"].map(key => Number(new RegExp(`\\b${key}="(\\d+)"`).exec(tri[1])?.[1]));
103
+ if (!c.every(k => Number.isInteger(k) && k >= 0 && k < count)) {
104
+ result = `a triangle of object ${id} in ${file} names a vertex it doesn't have`;
105
+ break;
106
+ }
107
+ corners.push(c[0], c[1], c[2]);
108
+ }
109
+ if (typeof result !== "string")
110
+ result.corners = Uint32Array.from(corners);
111
+ }
112
+ cache.set(id, result);
113
+ return result;
114
+ }
115
+ /** An object's triangles in the build frame: its own mesh, or its components' meshes, each through its transform. */
116
+ async function collect(read, file, id, transform, out, budget, depth = 0) {
117
+ if (depth > MAX_DEPTH)
118
+ return "its components nest too deeply";
119
+ const model = await read(file);
120
+ if (typeof model === "string")
121
+ return model;
122
+ const body = model.objects.get(id);
123
+ if (body === undefined)
124
+ return `object ${id} is missing from ${file}`;
125
+ const mesh = /<(?:\w+:)?mesh\b[^>]*>([\s\S]*?)<\/(?:\w+:)?mesh>/.exec(body)?.[1];
126
+ if (mesh) {
127
+ const parsedMesh = parseMesh(model, file, id, mesh);
128
+ if (typeof parsedMesh === "string")
129
+ return parsedMesh;
130
+ const t = transform, v = parsedMesh.vertices, corners = parsedMesh.corners;
131
+ // Checked before each mesh is expanded: nested components placing one mesh many times stop here, not in memory.
132
+ if (out.length / 9 + corners.length / 3 > budget)
133
+ return `it has more triangles than this call's remaining ${Math.max(0, Math.floor(budget))} of ${MAX_TOTAL_TRIANGLES}`;
134
+ // A mirroring placement (negative determinant) turns the surface inside out: each triangle's winding is reversed.
135
+ const mirrored = t[0] * (t[4] * t[8] - t[5] * t[7]) - t[1] * (t[3] * t[8] - t[5] * t[6]) + t[2] * (t[3] * t[7] - t[4] * t[6]) < 0;
136
+ for (let i = 0; i < corners.length; i += 3)
137
+ for (const k of mirrored ? [0, 2, 1] : [0, 1, 2]) {
138
+ const c = corners[i + k];
139
+ const x = v[c * 3], y = v[c * 3 + 1], z = v[c * 3 + 2];
140
+ out.push(x * t[0] + y * t[3] + z * t[6] + t[9], x * t[1] + y * t[4] + z * t[7] + t[10], x * t[2] + y * t[5] + z * t[8] + t[11]);
141
+ }
142
+ return undefined;
143
+ }
144
+ for (const component of body.matchAll(/<(?:\w+:)?component\b([^>]*)\/?>/g)) {
145
+ const child = /\bobjectid="(\d+)"/.exec(component[1])?.[1];
146
+ if (!child)
147
+ continue;
148
+ const childFile = /\b(?:\w+:)?path="\/?([^"]+)"/.exec(component[1])?.[1] ?? file;
149
+ const problem = await collect(read, childFile, child, compose(matrix(/\btransform="([^"]+)"/.exec(component[1])?.[1]), transform), out, budget, depth + 1);
150
+ if (problem)
151
+ return problem;
152
+ }
153
+ return undefined;
154
+ }
155
+ /** A binary STL of a flat triangle list, with each facet's normal. */
156
+ function stl(values) {
157
+ const count = values.length / 9;
158
+ const buffer = Buffer.alloc(84 + count * 50);
159
+ buffer.write("counterpart_part_meshes", 0, "ascii");
160
+ buffer.writeUInt32LE(count, 80);
161
+ for (let i = 0; i < count; i++) {
162
+ const p = values.slice(i * 9, i * 9 + 9); // nine numbers: cheap beside the file write
163
+ const u = [p[3] - p[0], p[4] - p[1], p[5] - p[2]], v = [p[6] - p[0], p[7] - p[1], p[8] - p[2]];
164
+ const n = [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]];
165
+ const length = Math.hypot(n[0], n[1], n[2]) || 1;
166
+ const at = 84 + i * 50;
167
+ n.forEach((value, k) => buffer.writeFloatLE(value / length, at + k * 4));
168
+ p.forEach((value, k) => buffer.writeFloatLE(value, at + 12 + k * 4));
169
+ }
170
+ return buffer;
171
+ }
172
+ const slug = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "part";
173
+ /** A new folder inside out_dir, named after the 3MF; nothing that exists is reused or overwritten. */
174
+ async function newFolder(outDir, base) {
175
+ const parent = await fs.realpath(outDir).catch(() => fail("out_dir must be an existing folder."));
176
+ if (!(await fs.stat(parent)).isDirectory())
177
+ fail("out_dir must be an existing folder.");
178
+ for (let n = 1; n <= 1000; n++) {
179
+ const folder = path.join(parent, `${slug(base)}-parts-${n}`);
180
+ try {
181
+ await fs.mkdir(folder);
182
+ return folder;
183
+ }
184
+ catch (error) {
185
+ if (error.code !== "EEXIST")
186
+ throw error;
187
+ }
188
+ }
189
+ return fail("out_dir already holds 1000 part folders for this 3MF; choose another out_dir.");
190
+ }
191
+ export async function partMeshes(args) {
192
+ if (Object.keys(args).some(key => key !== "three_mf_path" && key !== "out_dir"))
193
+ fail("counterpart_part_meshes accepts only three_mf_path and out_dir.");
194
+ if (typeof args.three_mf_path !== "string" || !args.three_mf_path.trim())
195
+ fail("three_mf_path must name a 3MF file.");
196
+ if (typeof args.out_dir !== "string" || !args.out_dir.trim())
197
+ fail("out_dir must name an existing folder.");
198
+ const source = path.resolve(args.three_mf_path);
199
+ const plates = await listModelPlates(source);
200
+ const { zip } = await readSafe3mfArchive(source);
201
+ const settings = await zip.file("Metadata/model_settings.config")?.async("string") ?? "";
202
+ const hasPlates = /<plate\b/.test(settings);
203
+ const colours = new Map(plates.project_filaments.flatMap(f => f.colour && /^#[0-9A-Fa-f]{6}/.test(f.colour) ? [[f.index, f.colour.slice(0, 7).toUpperCase()]] : []));
204
+ const read = modelReader(zip);
205
+ const root = await read(ROOT);
206
+ if (typeof root === "string")
207
+ fail(`This 3MF has no model to draw: ${root}.`);
208
+ const rootScale = root.scale;
209
+ const items = [...(await zip.file(ROOT).async("string")).matchAll(/<(?:\w+:)?item\b([^>]*)\/?>/g)].map(item => item[1]);
210
+ if (!plates.plates.some(plate => plate.parts.length))
211
+ fail("This 3MF has no printable part to draw.");
212
+ const folder = await newFolder(args.out_dir, path.basename(source, path.extname(source)));
213
+ const parts = [];
214
+ const skipped = [];
215
+ let written = 0;
216
+ try {
217
+ for (const plate of plates.plates)
218
+ if (plate.parts_truncated)
219
+ skipped.push({ id: `plate ${plate.index + 1}`, name: plate.name, reason: `${plate.parts_truncated} more parts beyond the first 1000 on this plate were not read` });
220
+ for (const plate of plates.plates)
221
+ for (const itemIndex of plate.build_items) {
222
+ const item = items[itemIndex];
223
+ if (!item || /\bprintable="(?:0|false)"/.test(item))
224
+ continue;
225
+ const objectId = /\bobjectid="(\d+)"/.exec(item)?.[1];
226
+ for (const part of plate.parts.filter(p => String(p.build_object_id) === objectId)) {
227
+ const file = part.path?.replace(/^\//, "") ?? ROOT;
228
+ // Each place the object puts this mesh: itself, or every component that names it (one mesh placed twice is two
229
+ // parts on the plate, like a plain 3MF's pair of wheels).
230
+ // Object ids are local to each model file: only a part in the root model with the build object's own id is that
231
+ // object's own mesh (Codex review, #169).
232
+ const placements = String(part.object_id) === objectId && file === ROOT ? [undefined]
233
+ : [...(root.objects.get(objectId ?? "") ?? "").matchAll(/<(?:\w+:)?component\b([^>]*)\/?>/g)]
234
+ .map(match => match[1]).filter(attrs => /\bobjectid="(\d+)"/.exec(attrs)?.[1] === String(part.object_id)
235
+ && (/\b(?:\w+:)?path="\/?([^"]+)"/.exec(attrs)?.[1] ?? ROOT) === file);
236
+ if (!placements.length) {
237
+ skipped.push({ id: `${itemIndex + 1}/${part.object_id}`, name: part.name, reason: `its component is missing from object ${objectId}` });
238
+ continue;
239
+ }
240
+ for (const [copy, component] of placements.entries()) {
241
+ const id = copy ? `${itemIndex + 1}/${part.object_id}/${copy + 1}` : `${itemIndex + 1}/${part.object_id}`;
242
+ const triangles = [];
243
+ let problem;
244
+ try {
245
+ const placed = matrix(/\btransform="([^"]+)"/.exec(item)?.[1]);
246
+ const budget = MAX_TOTAL_TRIANGLES - written;
247
+ problem = component === undefined ? await collect(read, ROOT, objectId, placed, triangles, budget)
248
+ : await collect(read, file, String(part.object_id), compose(matrix(/\btransform="([^"]+)"/.exec(component)?.[1]), placed), triangles, budget);
249
+ }
250
+ catch (error) {
251
+ // A malformed transform spoils this part only: it is listed with why, and the others are still written.
252
+ if (!(error instanceof PartMeshesError))
253
+ throw error;
254
+ problem = error.message;
255
+ }
256
+ if (!problem && !triangles.length)
257
+ problem = "it has no triangles";
258
+ // The root model's unit covers every model part and transform in the package (3MF core spec, 3.4).
259
+ if (rootScale !== 1)
260
+ for (let i = 0; i < triangles.length; i++)
261
+ triangles[i] *= rootScale;
262
+ if (problem) {
263
+ skipped.push({ id, name: part.name, reason: problem });
264
+ continue;
265
+ }
266
+ written += triangles.length / 9;
267
+ const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
268
+ for (let i = 0; i < triangles.length; i++) {
269
+ min[i % 3] = Math.min(min[i % 3], triangles[i]);
270
+ max[i % 3] = Math.max(max[i % 3], triangles[i]);
271
+ }
272
+ const stlPath = path.join(folder, `${parts.length + 1}-${slug(part.name)}.stl`);
273
+ await fs.writeFile(stlPath, stl(triangles), { flag: "wx" });
274
+ const colour = colours.get(part.filament);
275
+ parts.push({
276
+ id, name: part.name,
277
+ ...(hasPlates ? { plate: plate.index + 1 } : {}),
278
+ ...(colour ? { color: colour } : {}),
279
+ filament: part.filament,
280
+ ...(part.painted ? { painted: true } : {}),
281
+ stl_path: stlPath,
282
+ triangles: triangles.length / 9,
283
+ size_mm: [0, 1, 2].map(k => Math.round((max[k] - min[k]) * 1000) / 1000),
284
+ });
285
+ }
286
+ }
287
+ }
288
+ }
289
+ catch (error) {
290
+ // Nothing half-written is left behind.
291
+ await fs.rm(folder, { recursive: true, force: true }).catch(() => { });
292
+ throw error;
293
+ }
294
+ return { contract: COUNTERPART_CONTRACT, units: "mm", folder, parts, ...(skipped.length ? { skipped } : {}) };
295
+ }
296
+ export const PART_MESHES_OUTPUT_SCHEMA = {
297
+ type: "object",
298
+ properties: {
299
+ contract: { type: "string", const: COUNTERPART_CONTRACT },
300
+ units: { type: "string", const: "mm" },
301
+ folder: { type: "string", description: "The new folder the STLs were written in." },
302
+ parts: {
303
+ type: "array",
304
+ items: {
305
+ type: "object",
306
+ properties: {
307
+ id: { type: "string", description: "<build item, from 1>/<part's object id>, with /<n> for its second and later placements as a component: stable for the same file; a key, not to be parsed." },
308
+ name: { type: "string" },
309
+ plate: { type: "integer", minimum: 1, description: "Plate number from 1 (list_3mf_plates index + 1); absent without plate metadata." },
310
+ color: { type: "string", pattern: "^#[0-9A-F]{6}$", description: "The filament's colour as the 3MF declares it; absent when it declares none." },
311
+ filament: { type: "integer", minimum: 1 },
312
+ painted: { type: "boolean", const: true, description: "Slicer painting recolours some facets; color is the base filament's." },
313
+ stl_path: { type: "string" },
314
+ triangles: { type: "integer", minimum: 1 },
315
+ size_mm: { type: "array", items: { type: "number" }, minItems: 3, maxItems: 3 },
316
+ },
317
+ required: ["id", "name", "stl_path", "triangles", "size_mm"],
318
+ },
319
+ },
320
+ skipped: { type: "array", items: { type: "object", properties: { id: { type: "string" }, name: { type: "string" }, reason: { type: "string" } }, required: ["id", "name", "reason"] } },
321
+ },
322
+ required: ["contract", "units", "folder", "parts"],
323
+ };
@@ -48,6 +48,8 @@ export interface PlatePart {
48
48
  name: string;
49
49
  filament: number;
50
50
  painted?: true;
51
+ /** How many times the object places this mesh as a component, when more than once (a plain 3MF's wheels). */
52
+ components?: number;
51
53
  }
52
54
  type Settings = Map<string, string>;
53
55
  interface Part {
@@ -102,5 +104,6 @@ export declare function plateFilaments(zip: JSZip, settings: string, model: stri
102
104
  project: PlateFilament[];
103
105
  buildItems: Map<number, number[]>;
104
106
  parts: Map<number, PlatePart[]>;
107
+ partsTruncated: Map<number, number>;
105
108
  }>;
106
109
  export {};
@@ -168,20 +168,36 @@ export async function plateFilaments(zip, settings, model, plates, limits = PAIN
168
168
  const components = new Map();
169
169
  // Root objects that are meshes themselves (a plain 3MF): their own id is the part.
170
170
  const rootMeshes = new Set();
171
- for (const object of model.matchAll(/<(?:\w+:)?object\b[^>]*\bid="(\d+)"[^>]*>([\s\S]*?)<\/(?:\w+:)?object>/g)) {
172
- if (/<(?:\w+:)?mesh[\s>]/.test(object[2]))
173
- rootMeshes.add(object[1]);
171
+ // How often each root object places each component mesh, and the root model's own object names (a plain 3MF's).
172
+ const componentCounts = new Map();
173
+ const modelNames = new Map();
174
+ // An <object .../> closes itself: its (empty) body never runs on into the next object's.
175
+ for (const object of model.matchAll(/<(?:\w+:)?object\b([^>]*?)(?:\/>|>([\s\S]*?)<\/(?:\w+:)?object>)/g)) {
176
+ const objectId = /\bid="(\d+)"/.exec(object[1])?.[1];
177
+ if (!objectId)
178
+ continue;
179
+ const body = object[2] ?? "";
180
+ const named = /\bname="([^"]*)"/.exec(object[1])?.[1];
181
+ if (named)
182
+ modelNames.set(objectId, words(named));
183
+ if (/<(?:\w+:)?mesh[\s>]/.test(body))
184
+ rootMeshes.add(objectId);
174
185
  const parts = new Map();
175
- for (const component of object[2].matchAll(/<(?:\w+:)?component\b([^>]*)\/?>/g)) {
186
+ const counts = new Map();
187
+ for (const component of body.matchAll(/<(?:\w+:)?component\b([^>]*)\/?>/g)) {
176
188
  const path = /\b(?:\w+:)?path="\/?([^"]+)"/.exec(component[1])?.[1];
177
189
  const id = /\bobjectid="(\d+)"/.exec(component[1])?.[1];
178
190
  // Studio keys a component by (path, objectid); one without p:path names a mesh object in the root model
179
191
  // itself, keyed by the root's empty path (bbs_3mf.cpp:4131-4148, 3891).
180
- if (id)
192
+ if (id) {
181
193
  parts.set(id, path || "3D/3dmodel.model");
194
+ counts.set(id, (counts.get(id) ?? 0) + 1);
195
+ }
196
+ }
197
+ if (parts.size) {
198
+ components.set(objectId, parts);
199
+ componentCounts.set(objectId, counts);
182
200
  }
183
- if (parts.size)
184
- components.set(object[1], parts);
185
201
  }
186
202
  // Model object order (1-based in layer_config_ranges.xml): the build items' order, as Studio creates the objects.
187
203
  const buildItems = [...model.matchAll(/<(?:\w+:)?item\b([^>]*)\/?>/g)].map(item => item[1]);
@@ -242,6 +258,7 @@ export async function plateFilaments(zip, settings, model, plates, limits = PAIN
242
258
  const result = new Map();
243
259
  const plateItems = new Map();
244
260
  const plateParts = new Map();
261
+ const partsTruncated = new Map();
245
262
  const itemObject = buildItems.map(item => /\bobjectid="(\d+)"/.exec(item)?.[1]);
246
263
  // The plate's copies as root build items (0-based, in build order): a copy is its object's instance_id-th item.
247
264
  const plateItemsOf = (plate) => {
@@ -270,8 +287,10 @@ export async function plateFilaments(zip, settings, model, plates, limits = PAIN
270
287
  const entry = (id, name, filament) => {
271
288
  const path = meshes?.get(id) ?? (id === objectId && rootMeshes.has(objectId) ? ROOT_MODEL : undefined);
272
289
  const paint = path ? painting.get(`${path}#${id}`) : undefined;
273
- drawn.push({ object_id: Number(id), build_object_id: Number(objectId), ...(path && path !== "3D/3dmodel.model" ? { path: `/${path}` } : {}), name,
274
- filament: valid(filament) ? filament : 1, ...(paint?.states.size ? { painted: true } : {}) });
290
+ const placed = componentCounts.get(objectId)?.get(id) ?? 1;
291
+ drawn.push({ object_id: Number(id), build_object_id: Number(objectId), ...(path && path !== "3D/3dmodel.model" ? { path: `/${path}` } : {}),
292
+ name: name || modelNames.get(id) || modelNames.get(objectId) || "",
293
+ filament: valid(filament) ? filament : 1, ...(paint?.states.size ? { painted: true } : {}), ...(placed > 1 ? { components: placed } : {}) });
275
294
  };
276
295
  if (object?.parts.length) {
277
296
  for (const part of object.parts)
@@ -285,6 +304,8 @@ export async function plateFilaments(zip, settings, model, plates, limits = PAIN
285
304
  entry(objectId, object?.name ?? "", objectFilament);
286
305
  }
287
306
  plateParts.set(plate.number, drawn.slice(0, 1000));
307
+ if (drawn.length > 1000)
308
+ partsTruncated.set(plate.number, drawn.length - 1000);
288
309
  const used = new Map();
289
310
  const add = (index, name) => {
290
311
  if (!valid(index))
@@ -400,5 +421,5 @@ export async function plateFilaments(zip, settings, model, plates, limits = PAIN
400
421
  result.set(plate.number, [...used.entries()].sort((a, b) => a[0] - b[0]).map(([index, name]) => describe(index, project, name)));
401
422
  }
402
423
  // Every filament the project declares, used on a plate or not: slice_stl takes one profile per declared filament.
403
- return { plates: result, incomplete, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)), buildItems: plateItems, parts: plateParts };
424
+ return { plates: result, incomplete, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)), buildItems: plateItems, parts: plateParts, partsTruncated };
404
425
  }
@@ -35,6 +35,7 @@ export const REMOTE_SCOPES = {
35
35
  slice_stl: "design",
36
36
  lay_flat: "design",
37
37
  counterpart_make_3mf: "design",
38
+ counterpart_part_meshes: "design",
38
39
  // control
39
40
  bambu_connect_import_file: "control",
40
41
  camera_stream_start: "control",
@@ -90,6 +90,8 @@ export type PrinterInfo = {
90
90
  copies: boolean;
91
91
  orient: boolean;
92
92
  };
93
+ /** counterpart_part_meshes is here: one STL per printable part of any 3MF, with its filament's colour (#691, #845). */
94
+ partMeshes?: boolean;
93
95
  };
94
96
  };
95
97
  export declare const PRINTER_INFO_OUTPUT_SCHEMA: {
@@ -181,6 +183,10 @@ export declare const PRINTER_INFO_OUTPUT_SCHEMA: {
181
183
  type: string;
182
184
  description: string;
183
185
  };
186
+ partMeshes: {
187
+ type: string;
188
+ description: string;
189
+ };
184
190
  filaments: {
185
191
  type: string;
186
192
  enum: string[];
@@ -414,6 +420,10 @@ export declare const MAKE_3MF_OUTPUT_SCHEMA: {
414
420
  type: string;
415
421
  minimum: number;
416
422
  };
423
+ color: {
424
+ type: string;
425
+ pattern: string;
426
+ };
417
427
  };
418
428
  required: string[];
419
429
  };
@@ -44,6 +44,7 @@ export const PRINTER_INFO_OUTPUT_SCHEMA = {
44
44
  camera: { type: "string", enum: ["bambu-tcp", "rtsp", "http-snapshot", "none"] },
45
45
  cameraStream: { type: "boolean" },
46
46
  diagnostics: { type: "boolean", description: "counterpart_diagnostics is available." },
47
+ partMeshes: { type: "boolean", description: "counterpart_part_meshes is available." },
47
48
  filaments: { type: "string", enum: ["ams", "single", "none"] },
48
49
  pause: { type: "boolean" },
49
50
  resume: { type: "boolean" },
@@ -126,6 +127,7 @@ export const MAKE_3MF_OUTPUT_SCHEMA = {
126
127
  stl_path: { type: "string" },
127
128
  filament: { type: "integer", minimum: 1 },
128
129
  triangles: { type: "integer", minimum: 1 },
130
+ color: { type: "string", pattern: "^#[0-9A-F]{6}$" },
129
131
  },
130
132
  required: ["name", "stl_path", "filament", "triangles"],
131
133
  },
@@ -69,6 +69,8 @@ export type BlenderSetupReport = {
69
69
  target_problem?: "not-installed" | "several-modules";
70
70
  /** What the person can do, in plain words, when the add-on can't be checked or updated here (reason, target_problem). */
71
71
  message?: string;
72
+ /** not-configured: the server settings that connect Blender, for a setup screen or a log; never shown as the message. */
73
+ settings?: string[];
72
74
  /** The installed file's protocol is what the package expects. */
73
75
  current?: boolean;
74
76
  /** Set by update. */
@@ -120,6 +122,13 @@ export declare const BLENDER_SETUP_OUTPUT_SCHEMA: {
120
122
  readonly type: "string";
121
123
  readonly enum: readonly ["not-configured", "custom-command", "custom-package"];
122
124
  };
125
+ readonly settings: {
126
+ readonly type: "array";
127
+ readonly items: {
128
+ readonly type: "string";
129
+ };
130
+ readonly description: "not-configured: the server settings that connect Blender (BLENDER_MCP_COMMAND, BLENDER_MCP_ARGS).";
131
+ };
123
132
  readonly package: {
124
133
  readonly type: "string";
125
134
  readonly description: "The package as BLENDER_MCP_ARGS names it.";
@@ -145,7 +145,8 @@ class Serial {
145
145
  }
146
146
  }
147
147
  const UNSUPPORTED_MESSAGES = {
148
- "not-configured": "This printer MCP has no Blender bridge configured (BLENDER_MCP_COMMAND and BLENDER_MCP_ARGS). Set it up for MCP for Blender, then check again.",
148
+ // Shown as it is to a new tester (scan-to-make #851): plain words; the settings it needs are in `settings`.
149
+ "not-configured": "Blender isn't connected to your printer software yet. Scan cleanup can use it once it is; printing never needs it.",
149
150
  "custom-command": "This Blender bridge uses its own command, so its add-on is updated with that bridge's installer.",
150
151
  "custom-package": "This Blender bridge uses its own package, so its add-on is updated with that bridge's installer.",
151
152
  };
@@ -225,7 +226,8 @@ export class BlenderAddonSetup {
225
226
  const { host, port } = blenderAddress(this.env);
226
227
  const listening = await this.system.listening(host, port);
227
228
  if ("reason" in installer)
228
- return { supported: false, reason: installer.reason, listening, message: UNSUPPORTED_MESSAGES[installer.reason] };
229
+ return { supported: false, reason: installer.reason, listening, message: UNSUPPORTED_MESSAGES[installer.reason],
230
+ ...(installer.reason === "not-configured" ? { settings: ["BLENDER_MCP_COMMAND", "BLENDER_MCP_ARGS"] } : {}) };
229
231
  let live, liveError;
230
232
  if (listening) {
231
233
  try {
@@ -319,6 +321,7 @@ export const BLENDER_SETUP_OUTPUT_SCHEMA = {
319
321
  properties: {
320
322
  supported: { type: "boolean", description: "The configured bridge is the upstream MCP for Blender package run with uvx, so this tool can check and update its add-on." },
321
323
  reason: { type: "string", enum: ["not-configured", "custom-command", "custom-package"] },
324
+ settings: { type: "array", items: { type: "string" }, description: "not-configured: the server settings that connect Blender (BLENDER_MCP_COMMAND, BLENDER_MCP_ARGS)." },
322
325
  package: { type: "string", description: "The package as BLENDER_MCP_ARGS names it." },
323
326
  package_version: { type: "string" },
324
327
  expected_protocol: { type: "integer", description: "The add-on protocol the package needs." },