any2orca 0.4.1 → 0.6.0
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/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/dist/archive/objectWorldBboxXY.js +3 -2
- package/dist/archive/zip.d.ts +10 -13
- package/dist/archive/zip.js +17 -75
- package/dist/inspect.d.ts +1 -7
- package/dist/inspect.js +9 -3
- package/dist/project.js +4 -0
- package/dist/sources/bambuFamily.d.ts +2 -0
- package/dist/sources/bambuFamily.js +82 -0
- package/dist/sources/index.d.ts +6 -0
- package/dist/sources/index.js +9 -0
- package/dist/sources/prusa/convertSettings.d.ts +20 -0
- package/dist/sources/prusa/convertSettings.js +325 -0
- package/dist/sources/prusa/ini.d.ts +41 -0
- package/dist/sources/prusa/ini.js +106 -0
- package/dist/sources/prusa/keyMap.d.ts +56 -0
- package/dist/sources/prusa/keyMap.js +483 -0
- package/dist/sources/prusa/modelConfig.d.ts +50 -0
- package/dist/sources/prusa/modelConfig.js +83 -0
- package/dist/sources/prusa/prusa.d.ts +59 -0
- package/dist/sources/prusa/prusa.js +340 -0
- package/dist/sources/prusa/splitParts.d.ts +25 -0
- package/dist/sources/prusa/splitParts.js +77 -0
- package/dist/sources/reader.d.ts +42 -0
- package/dist/sources/reader.js +1 -0
- package/dist/stamp.d.ts +7 -0
- package/dist/stamp.js +12 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# any2orca
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Output-affecting
|
|
6
|
+
|
|
7
|
+
- **Six more PrusaSlicer settings are carried.** A trace of every dropped PrusaSlicer key through Bambu Studio's, OrcaSlicer's and Snapmaker Orca's rename tables found no missed rename, and six settings with the same meaning under another name, confirmed on both slicers' descriptions: "keep fan always on", automatic infill combination and its maximum layer height, a solid layer every N layers ("insert solid layers"), clockwise wall direction, support layers synchronized with the object (Snapmaker Orca's independent support layer height, inverted), and a filament's ramping lift (its Z-hop type). Only PrusaSlicer conversions change; the report's list of settings with no counterpart is shorter by those six.
|
|
8
|
+
- **A PrusaSlicer project's printer settings are the U1's.** The converter listed every mapped setting as changed by the creator, printer settings included, so a PrusaSlicer printer's retraction and single-extruder purge moves reached the file (Snapmaker Orca replaced them with its printer preset's on load, as the re-save of five converted files showed). Only print settings are listed now, as for a Bambu Studio family project, whose own list never names printer settings; the printer's values in a converted file are the U1 profile's.
|
|
9
|
+
|
|
10
|
+
## 0.5.0
|
|
11
|
+
|
|
12
|
+
### Output-affecting
|
|
13
|
+
|
|
14
|
+
- **The stamp records the source.** `Metadata/any2orca.json` in a converted file now has a `source` field: the project's format (`bambu-family` or `prusaslicer`) and the slicer version it was saved by. Nothing else in the file changes. A stamp without the field is from an earlier release and means the Bambu Studio family; `decodeStamp` reads both.
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- **PrusaSlicer projects convert.** A project saved by PrusaSlicer (2.2 to 2.9.6 tested) is read like one from the Bambu Studio family: its settings are translated to Snapmaker Orca's keys (390 of them have a rule; the ones with no counterpart are listed in the report), every filament is kept with the color PrusaSlicer shows, an object's parts become Snapmaker Orca's parts with their own filaments and settings, painting (multi-color, seams, supports, fuzzy skin) is carried, a color change at a height becomes a pause there (the U1 stops for the swap; Snapmaker Orca writes no G-code for a color change of its own), variable layer heights are kept, and the printer's own settings stay the U1's. Layer-range settings aren't carried yet; the report says so. `inspect()` names Prusa Research printers, and a project from a slicer built on PrusaSlicer (SuperSlicer, an older AnycubicSlicer) is still refused by name.
|
|
19
|
+
|
|
3
20
|
## 0.4.1
|
|
4
21
|
|
|
5
22
|
### Features
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# any2orca
|
|
2
2
|
|
|
3
|
-
Convert Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer
|
|
3
|
+
Convert Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer, Flash Studio and PrusaSlicer `.3mf` projects to Snapmaker U1 / Orca format, entirely on your own machine. One package: a command-line tool, a library for Node and browsers, and a ready-made Web Worker.
|
|
4
4
|
|
|
5
5
|
Formerly bambu2orca and the `@kuzuri.ao/b2o` CLI. Same conversion, now local: no account, no API key, no quota, and nothing you convert is sent anywhere.
|
|
6
6
|
|
|
@@ -64,8 +64,9 @@ export function objectWorldBboxXY(objectId, topModelText, partFileCache, zipEntr
|
|
|
64
64
|
for (const tag of componentTags) {
|
|
65
65
|
const path = componentAttr(tag, "p:path");
|
|
66
66
|
const subObjId = componentAttr(tag, "objectid");
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// The 3MF spec makes a component's transform optional (identity when absent); PrusaSlicer leaves it out.
|
|
68
|
+
const transform = componentAttr(tag, "transform") ?? "1 0 0 0 1 0 0 0 1 0 0 0";
|
|
69
|
+
if (!subObjId)
|
|
69
70
|
continue;
|
|
70
71
|
const [compR, compT] = parseMatrix(transform);
|
|
71
72
|
const [R, T] = compose(itemR, itemT, compR, compT);
|
package/dist/archive/zip.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
unpackedBytes: number;
|
|
11
|
-
}
|
|
12
|
-
export declare function prepareConvertRequest(fileBytes: Uint8Array, maxUnpackedBytes?: number): ParsedBambuProject;
|
|
1
|
+
import type { ConvertResponse } from "../schema.js";
|
|
2
|
+
import { type ParsedProject } from "../sources/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Unzips a source .3mf (already in memory as bytes), refuses what no reader converts, and hands the entries to
|
|
5
|
+
* the reader that recognizes them (`sources/`): the conversion request is the project's settings in Snapmaker
|
|
6
|
+
* Orca's keys, plus each top-level object's world-space bounding box (or its raw transform translation as a
|
|
7
|
+
* fallback when mesh geometry is missing), its plate assignment, and its name.
|
|
8
|
+
*/
|
|
9
|
+
export declare function prepareConvertRequest(fileBytes: Uint8Array, maxUnpackedBytes?: number): ParsedProject;
|
|
13
10
|
/**
|
|
14
11
|
* Apply a conversion response to the originally parsed project and
|
|
15
12
|
* produce the final Snapmaker Orca .3mf bytes, ready to offer as a
|
|
@@ -20,4 +17,4 @@ export declare function prepareConvertRequest(fileBytes: Uint8Array, maxUnpacked
|
|
|
20
17
|
* response's merged project_settings.config plus every generated/
|
|
21
18
|
* passthrough config file. `extraEntries` are added last (the output stamp).
|
|
22
19
|
*/
|
|
23
|
-
export declare function applyConvertResponse(parsed:
|
|
20
|
+
export declare function applyConvertResponse(parsed: ParsedProject, response: ConvertResponse, extraEntries?: Record<string, Uint8Array>): Uint8Array;
|
package/dist/archive/zip.js
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
import { zipSync } from "fflate";
|
|
3
3
|
import { Any2orcaError } from "../errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { findSourceReader } from "../sources/index.js";
|
|
5
5
|
import { adaptModelSettings } from "./adaptModelSettings.js";
|
|
6
6
|
import { setApplicationMetadata } from "./setApplicationMetadata.js";
|
|
7
|
-
import { objectWorldBboxXY } from "./objectWorldBboxXY.js";
|
|
8
|
-
import { parseItemPositions } from "./parseItemPositions.js";
|
|
9
7
|
import { MODEL_SETTINGS_PATH, PROJECT_SETTINGS_PATH, SPECIAL_HANDLING, TOP_MODEL_PATH } from "./paths.js";
|
|
10
|
-
import { parseObjectMetadata } from "./parseObjectMetadata.js";
|
|
11
|
-
import { parsePlateAssignments } from "./parsePlateAssignments.js";
|
|
12
8
|
import { recenterAssembleItems } from "./recenterAssembleItems.js";
|
|
13
9
|
import { recenterBuildItems } from "./recenterBuildItems.js";
|
|
14
10
|
import { formatSize, LARGE_PROJECT_BYTES, safeUnzipSync } from "./safeUnzip.js";
|
|
15
11
|
import { shouldDropFromBambu } from "./shouldDropFromBambu.js";
|
|
16
|
-
import { tolerantJsonParse } from "./tolerantJsonParse.js";
|
|
17
12
|
const utf8Decoder = new TextDecoder("utf-8");
|
|
18
13
|
const utf8Encoder = new TextEncoder();
|
|
19
|
-
/** The largest main model file read as text: the engine's longest string is about 512 MB, and UTF-8 never takes fewer bytes than characters. */
|
|
20
|
-
const MAX_TOP_MODEL_BYTES = 500 * 1024 * 1024;
|
|
21
|
-
/**
|
|
22
|
-
* Unzip a source .3mf (already in memory as bytes) and build the conversion request payload: the
|
|
23
|
-
* full project_settings.config JSON, plus each top-level object's
|
|
24
|
-
* world-space bounding box (or its raw transform translation as a
|
|
25
|
-
* fallback when mesh geometry is missing), its plate assignment, and its name.
|
|
26
|
-
*/
|
|
27
14
|
/** Where PrusaSlicer and the slicers built on it keep a project's print settings. */
|
|
28
15
|
const OTHER_FORMAT_SETTINGS_PATH = "Metadata/Slic3r_PE.config";
|
|
29
16
|
/**
|
|
@@ -35,6 +22,12 @@ function otherFormatSlicer(settings) {
|
|
|
35
22
|
const name = /^; generated by ([A-Za-z][A-Za-z0-9]{1,30}(?: [A-Za-z][A-Za-z0-9]{1,30})?) v?\d/.exec(firstLine)?.[1];
|
|
36
23
|
return name ?? "PrusaSlicer or a slicer based on it";
|
|
37
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Unzips a source .3mf (already in memory as bytes), refuses what no reader converts, and hands the entries to
|
|
27
|
+
* the reader that recognizes them (`sources/`): the conversion request is the project's settings in Snapmaker
|
|
28
|
+
* Orca's keys, plus each top-level object's world-space bounding box (or its raw transform translation as a
|
|
29
|
+
* fallback when mesh geometry is missing), its plate assignment, and its name.
|
|
30
|
+
*/
|
|
38
31
|
export function prepareConvertRequest(fileBytes, maxUnpackedBytes) {
|
|
39
32
|
const zipEntries = safeUnzipSync(fileBytes, maxUnpackedBytes);
|
|
40
33
|
const warnings = [];
|
|
@@ -47,73 +40,22 @@ export function prepareConvertRequest(fileBytes, maxUnpackedBytes) {
|
|
|
47
40
|
if (Object.keys(zipEntries).some((name) => /^Metadata\/plate_\d+\.gcode$/i.test(name))) {
|
|
48
41
|
throw new Any2orcaError("invalid_project", "This is a sliced plate file (.gcode.3mf): it holds G-code for the printer it was sliced for, not a project to convert. Convert the project file it was sliced from instead.");
|
|
49
42
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
const reader = findSourceReader(zipEntries);
|
|
44
|
+
if (reader)
|
|
45
|
+
return reader.read(zipEntries, { unpackedBytes, warnings });
|
|
46
|
+
// No reader knows this file. Say which kind of file it is.
|
|
47
|
+
// The slicers built on PrusaSlicer (SuperSlicer, an older AnycubicSlicer) keep their print settings in
|
|
48
|
+
// PrusaSlicer's file and format, with keys of their own: a project, but not one this converts.
|
|
53
49
|
const otherFormatSettings = zipEntries[OTHER_FORMAT_SETTINGS_PATH];
|
|
54
|
-
if (
|
|
50
|
+
if (otherFormatSettings) {
|
|
55
51
|
const slicer = otherFormatSlicer(otherFormatSettings);
|
|
56
|
-
throw new Any2orcaError("unsupported_slicer", `This project was saved by ${slicer}, and only projects from Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer
|
|
52
|
+
throw new Any2orcaError("unsupported_slicer", `This project was saved by ${slicer}, and only projects from Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer, Flash Studio and PrusaSlicer can be converted.`, { slicer });
|
|
57
53
|
}
|
|
58
54
|
// A zip that isn't a 3MF at all (no model part, no print settings): a bundle of STL files, say.
|
|
59
|
-
if (!
|
|
55
|
+
if (!zipEntries[TOP_MODEL_PATH]) {
|
|
60
56
|
throw new Any2orcaError("invalid_file", "This file is a zip, but not a 3MF project, and holds no 3MF to convert. Model files such as STLs don't need converting: open them in Snapmaker Orca and choose a U1 profile.");
|
|
61
57
|
}
|
|
62
|
-
|
|
63
|
-
throw new Any2orcaError("invalid_file", "This 3MF holds only the model, with no print settings, so there's nothing to convert: open it in Snapmaker Orca and choose a U1 profile.");
|
|
64
|
-
}
|
|
65
|
-
let parsed;
|
|
66
|
-
try {
|
|
67
|
-
parsed = tolerantJsonParse(utf8Decoder.decode(projectSettingsBytes));
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
71
|
-
throw new Any2orcaError("invalid_file", "This project's print settings are damaged, so it can't be converted. Re-saving the project in its slicer usually fixes this.", { cause: new Error(`${PROJECT_SETTINGS_PATH} isn't valid JSON (${reason})`) });
|
|
72
|
-
}
|
|
73
|
-
const { value: projectSettings, trailingText } = parsed;
|
|
74
|
-
if (trailingText.trim()) {
|
|
75
|
-
warnings.push(` (note: ignored ${trailingText.length} bytes of trailing non-JSON content after project_settings.config, e.g. ${JSON.stringify(trailingText.slice(0, 60))})`);
|
|
76
|
-
}
|
|
77
|
-
const topModelBytes = zipEntries[TOP_MODEL_PATH];
|
|
78
|
-
if (!topModelBytes) {
|
|
79
|
-
throw new Any2orcaError("invalid_file", "This 3MF has no model in it, so there's nothing to convert.");
|
|
80
|
-
}
|
|
81
|
-
// The main model is read as text, and a JavaScript string can't be longer than about 512 MB. Slicers keep big
|
|
82
|
-
// meshes in their own part files (3D/Objects/), which are scanned in chunks; this only stops an odd file.
|
|
83
|
-
if (topModelBytes.length > MAX_TOP_MODEL_BYTES) {
|
|
84
|
-
throw new Any2orcaError("invalid_project", `This project's main model file is ${Math.round(topModelBytes.length / 1024 / 1024)} MB, more than the ${MAX_TOP_MODEL_BYTES / 1024 / 1024} MB that can be read in one piece. Re-saving the project in its slicer usually stores the meshes as separate files, which have no such limit.`);
|
|
85
|
-
}
|
|
86
|
-
const topModelText = utf8Decoder.decode(topModelBytes);
|
|
87
|
-
const modelSettingsBytes = zipEntries[MODEL_SETTINGS_PATH];
|
|
88
|
-
const modelSettingsText = modelSettingsBytes ? utf8Decoder.decode(modelSettingsBytes) : "";
|
|
89
|
-
const itemPositions = parseItemPositions(topModelText);
|
|
90
|
-
// Refused before any per-object work, which scans the model once per object.
|
|
91
|
-
const itemCount = Object.keys(itemPositions).length;
|
|
92
|
-
if (itemCount > MAX_OBJECTS) {
|
|
93
|
-
throw new Any2orcaError("invalid_project", `This project has ${itemCount} objects, more than the ${MAX_OBJECTS} a conversion supports.`);
|
|
94
|
-
}
|
|
95
|
-
const plateAssignments = modelSettingsText ? parsePlateAssignments(modelSettingsText) : {};
|
|
96
|
-
const objectMetadata = parseObjectMetadata(topModelText, modelSettingsText);
|
|
97
|
-
const partFileCache = new Map();
|
|
98
|
-
const objects = Object.entries(itemPositions).map(([id, fallbackXy]) => {
|
|
99
|
-
const bbox = objectWorldBboxXY(id, topModelText, partFileCache, zipEntries);
|
|
100
|
-
const plate = plateAssignments[id];
|
|
101
|
-
const meta = objectMetadata[id];
|
|
102
|
-
return {
|
|
103
|
-
id,
|
|
104
|
-
...(meta?.name ? { name: meta.name } : {}),
|
|
105
|
-
...(meta?.sequence !== undefined ? { sequence: meta.sequence } : {}),
|
|
106
|
-
...(meta?.isAssembly !== undefined ? { isAssembly: meta.isAssembly } : {}),
|
|
107
|
-
...(plate !== undefined ? { plate } : {}),
|
|
108
|
-
...(bbox ? { bbox } : { bbox: null, fallbackXy }),
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
return {
|
|
112
|
-
zipEntries,
|
|
113
|
-
request: { projectSettings: projectSettings, objects },
|
|
114
|
-
warnings,
|
|
115
|
-
unpackedBytes,
|
|
116
|
-
};
|
|
58
|
+
throw new Any2orcaError("invalid_file", "This 3MF holds only the model, with no print settings, so there's nothing to convert: open it in Snapmaker Orca and choose a U1 profile.");
|
|
117
59
|
}
|
|
118
60
|
/**
|
|
119
61
|
* Apply a conversion response to the originally parsed project and
|
package/dist/inspect.d.ts
CHANGED
|
@@ -52,12 +52,6 @@ export interface Inspection {
|
|
|
52
52
|
*/
|
|
53
53
|
unpackedBytes: number;
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
* The source printer's maker, from `printer_model` (e.g. "Creality K2 Plus"),
|
|
57
|
-
* falling back to the printer named after "@" in the process preset (e.g.
|
|
58
|
-
* "0.20mm Standard @BBL X1C"). Not the 3MF's Application tag: Anycubic
|
|
59
|
-
* Slicer Next writes "BambuStudio" there.
|
|
60
|
-
*/
|
|
61
|
-
export declare function detectSourceVendor(printerModel: string | null, sourcePresetName?: string | null): SourceVendor;
|
|
55
|
+
export declare function detectSourceVendor(printerModel: string | null, sourcePresetName?: string | null, printerNotes?: string | null, printerPresetName?: string | null): SourceVendor;
|
|
62
56
|
/** Builds an {@link Inspection} from a parsed project's settings and objects. */
|
|
63
57
|
export declare function inspectProject(projectSettings: Record<string, unknown>, objects: ConvertObject[], warnings: readonly string[], unpackedBytes: number): Inspection;
|
package/dist/inspect.js
CHANGED
|
@@ -45,9 +45,15 @@ function guessMaterial(presetName) {
|
|
|
45
45
|
* "0.20mm Standard @BBL X1C"). Not the 3MF's Application tag: Anycubic
|
|
46
46
|
* Slicer Next writes "BambuStudio" there.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
/** PrusaSlicer's printer profiles name their maker in `printer_notes` ("PRINTER_VENDOR_PRUSA3D"), where the model name doesn't. */
|
|
49
|
+
const NOTES_VENDORS = { PRUSA3D: "prusa", CREALITY: "creality", ANYCUBIC: "anycubic", ELEGOO: "elegoo", FLASHFORGE: "flashforge", SNAPMAKER: "snapmaker", BBL: "bambu" };
|
|
50
|
+
export function detectSourceVendor(printerModel, sourcePresetName = null, printerNotes = null, printerPresetName = null) {
|
|
49
51
|
const presetPrinter = sourcePresetName?.split("@")[1]?.trim() ?? null;
|
|
50
|
-
|
|
52
|
+
const notesVendor = /\bPRINTER_VENDOR_([A-Z0-9]{1,20})\b/.exec(printerNotes ?? "")?.[1];
|
|
53
|
+
if (notesVendor && Object.hasOwn(NOTES_VENDORS, notesVendor))
|
|
54
|
+
return NOTES_VENDORS[notesVendor];
|
|
55
|
+
// The printer preset's name last: PrusaSlicer's `printer_model` is a code ("COREONE"), its preset name says "Prusa CORE One".
|
|
56
|
+
for (const candidate of [printerModel, presetPrinter, printerPresetName]) {
|
|
51
57
|
if (!candidate)
|
|
52
58
|
continue;
|
|
53
59
|
const match = VENDOR_PATTERNS.find(({ pattern }) => pattern.test(candidate));
|
|
@@ -92,7 +98,7 @@ export function inspectProject(projectSettings, objects, warnings, unpackedBytes
|
|
|
92
98
|
sourcePresetName,
|
|
93
99
|
tierName: typeof projectSettings.print_settings_id === "string" ? parseTierName(projectSettings.print_settings_id) : null,
|
|
94
100
|
printerModel,
|
|
95
|
-
sourceVendor: detectSourceVendor(printerModel, sourcePresetName),
|
|
101
|
+
sourceVendor: detectSourceVendor(printerModel, sourcePresetName, typeof projectSettings.printer_notes === "string" ? projectSettings.printer_notes.slice(0, 4000) : null, asDisplayString(projectSettings.printer_settings_id)),
|
|
96
102
|
slicerVersion: asDisplayString(projectSettings.version),
|
|
97
103
|
sourcePrintableArea: Array.isArray(printableArea) && printableArea.length <= 64 && printableArea.every((p) => typeof p === "string")
|
|
98
104
|
? printableArea.slice()
|
package/dist/project.js
CHANGED
|
@@ -264,6 +264,9 @@ export class Project {
|
|
|
264
264
|
throw new Any2orcaError("invalid_project", `This project can't be converted: ${describeIssues(checked.error.issues)}.`);
|
|
265
265
|
}
|
|
266
266
|
const response = checked.data;
|
|
267
|
+
// The slicer version the source file names, when it's one plain line; the stamp takes nothing else from the file.
|
|
268
|
+
const rawSourceVersion = this.request.projectSettings.version;
|
|
269
|
+
const sourceVersion = typeof rawSourceVersion === "string" && /^[\x20-\x7e]{1,64}$/.test(rawSourceVersion) ? rawSourceVersion : null;
|
|
267
270
|
const stamp = options.stamp === false
|
|
268
271
|
? null
|
|
269
272
|
: {
|
|
@@ -272,6 +275,7 @@ export class Project {
|
|
|
272
275
|
version: VERSION,
|
|
273
276
|
profiles: { version: catalog.index.dataVersion, tracks: `${catalog.index.slicer.name} ${catalog.index.slicer.version}` },
|
|
274
277
|
profileId,
|
|
278
|
+
source: { format: this.parsed.source, ...(sourceVersion !== null ? { slicerVersion: sourceVersion } : {}) },
|
|
275
279
|
options: {
|
|
276
280
|
highFlowHotends,
|
|
277
281
|
hardenedNozzles: options.hardenedNozzles === true,
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The reader for Bambu Studio and the slicers built on it (Creality Print,
|
|
4
|
+
* Anycubic Slicer Next, ElegooSlicer, Flash Studio): a project's settings are
|
|
5
|
+
* JSON in `Metadata/project_settings.config`, per-object settings and plates
|
|
6
|
+
* in `Metadata/model_settings.config`, the build in `3D/3dmodel.model`.
|
|
7
|
+
*/
|
|
8
|
+
import { Any2orcaError } from "../errors.js";
|
|
9
|
+
import { MAX_OBJECTS } from "../schema.js";
|
|
10
|
+
import { objectWorldBboxXY } from "../archive/objectWorldBboxXY.js";
|
|
11
|
+
import { parseItemPositions } from "../archive/parseItemPositions.js";
|
|
12
|
+
import { MODEL_SETTINGS_PATH, PROJECT_SETTINGS_PATH, TOP_MODEL_PATH } from "../archive/paths.js";
|
|
13
|
+
import { parseObjectMetadata } from "../archive/parseObjectMetadata.js";
|
|
14
|
+
import { parsePlateAssignments } from "../archive/parsePlateAssignments.js";
|
|
15
|
+
import { tolerantJsonParse } from "../archive/tolerantJsonParse.js";
|
|
16
|
+
const utf8Decoder = new TextDecoder("utf-8");
|
|
17
|
+
/** The largest main model file read as text: the engine's longest string is about 512 MB, and UTF-8 never takes fewer bytes than characters. */
|
|
18
|
+
const MAX_TOP_MODEL_BYTES = 500 * 1024 * 1024;
|
|
19
|
+
export const bambuFamilyReader = {
|
|
20
|
+
format: "bambu-family",
|
|
21
|
+
detect(entries) {
|
|
22
|
+
return entries[PROJECT_SETTINGS_PATH] !== undefined;
|
|
23
|
+
},
|
|
24
|
+
read(zipEntries, { unpackedBytes, warnings }) {
|
|
25
|
+
const projectSettingsBytes = zipEntries[PROJECT_SETTINGS_PATH];
|
|
26
|
+
if (!projectSettingsBytes)
|
|
27
|
+
throw new Any2orcaError("invalid_file", "This 3MF holds only the model, with no print settings, so there's nothing to convert.");
|
|
28
|
+
let parsed;
|
|
29
|
+
try {
|
|
30
|
+
parsed = tolerantJsonParse(utf8Decoder.decode(projectSettingsBytes));
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
34
|
+
throw new Any2orcaError("invalid_file", "This project's print settings are damaged, so it can't be converted. Re-saving the project in its slicer usually fixes this.", { cause: new Error(`${PROJECT_SETTINGS_PATH} isn't valid JSON (${reason})`) });
|
|
35
|
+
}
|
|
36
|
+
const { value: projectSettings, trailingText } = parsed;
|
|
37
|
+
if (trailingText.trim()) {
|
|
38
|
+
warnings.push(` (note: ignored ${trailingText.length} bytes of trailing non-JSON content after project_settings.config, e.g. ${JSON.stringify(trailingText.slice(0, 60))})`);
|
|
39
|
+
}
|
|
40
|
+
const topModelBytes = zipEntries[TOP_MODEL_PATH];
|
|
41
|
+
if (!topModelBytes) {
|
|
42
|
+
throw new Any2orcaError("invalid_file", "This 3MF has no model in it, so there's nothing to convert.");
|
|
43
|
+
}
|
|
44
|
+
// The main model is read as text, and a JavaScript string can't be longer than about 512 MB. Slicers keep big
|
|
45
|
+
// meshes in their own part files (3D/Objects/), which are scanned in chunks; this only stops an odd file.
|
|
46
|
+
if (topModelBytes.length > MAX_TOP_MODEL_BYTES) {
|
|
47
|
+
throw new Any2orcaError("invalid_project", `This project's main model file is ${Math.round(topModelBytes.length / 1024 / 1024)} MB, more than the ${MAX_TOP_MODEL_BYTES / 1024 / 1024} MB that can be read in one piece. Re-saving the project in its slicer usually stores the meshes as separate files, which have no such limit.`);
|
|
48
|
+
}
|
|
49
|
+
const topModelText = utf8Decoder.decode(topModelBytes);
|
|
50
|
+
const modelSettingsBytes = zipEntries[MODEL_SETTINGS_PATH];
|
|
51
|
+
const modelSettingsText = modelSettingsBytes ? utf8Decoder.decode(modelSettingsBytes) : "";
|
|
52
|
+
const itemPositions = parseItemPositions(topModelText);
|
|
53
|
+
// Refused before any per-object work, which scans the model once per object.
|
|
54
|
+
const itemCount = Object.keys(itemPositions).length;
|
|
55
|
+
if (itemCount > MAX_OBJECTS) {
|
|
56
|
+
throw new Any2orcaError("invalid_project", `This project has ${itemCount} objects, more than the ${MAX_OBJECTS} a conversion supports.`);
|
|
57
|
+
}
|
|
58
|
+
const plateAssignments = modelSettingsText ? parsePlateAssignments(modelSettingsText) : {};
|
|
59
|
+
const objectMetadata = parseObjectMetadata(topModelText, modelSettingsText);
|
|
60
|
+
const partFileCache = new Map();
|
|
61
|
+
const objects = Object.entries(itemPositions).map(([id, fallbackXy]) => {
|
|
62
|
+
const bbox = objectWorldBboxXY(id, topModelText, partFileCache, zipEntries);
|
|
63
|
+
const plate = plateAssignments[id];
|
|
64
|
+
const meta = objectMetadata[id];
|
|
65
|
+
return {
|
|
66
|
+
id,
|
|
67
|
+
...(meta?.name ? { name: meta.name } : {}),
|
|
68
|
+
...(meta?.sequence !== undefined ? { sequence: meta.sequence } : {}),
|
|
69
|
+
...(meta?.isAssembly !== undefined ? { isAssembly: meta.isAssembly } : {}),
|
|
70
|
+
...(plate !== undefined ? { plate } : {}),
|
|
71
|
+
...(bbox ? { bbox } : { bbox: null, fallbackXy }),
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
source: "bambu-family",
|
|
76
|
+
zipEntries,
|
|
77
|
+
request: { projectSettings: projectSettings, objects },
|
|
78
|
+
warnings,
|
|
79
|
+
unpackedBytes,
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceReader } from "./reader.js";
|
|
2
|
+
export type { ParsedProject, ReadContext, SourceFormat, SourceReader } from "./reader.js";
|
|
3
|
+
/** Every reader, in the order they're tried. */
|
|
4
|
+
export declare const SOURCE_READERS: readonly SourceReader[];
|
|
5
|
+
/** The reader for these zip entries, or null when no reader recognizes them. */
|
|
6
|
+
export declare function findSourceReader(entries: Record<string, Uint8Array>): SourceReader | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { bambuFamilyReader } from "./bambuFamily.js";
|
|
3
|
+
import { prusaReader } from "./prusa/prusa.js";
|
|
4
|
+
/** Every reader, in the order they're tried. */
|
|
5
|
+
export const SOURCE_READERS = [bambuFamilyReader, prusaReader];
|
|
6
|
+
/** The reader for these zip entries, or null when no reader recognizes them. */
|
|
7
|
+
export function findSourceReader(entries) {
|
|
8
|
+
return SOURCE_READERS.find((reader) => reader.detect(entries)) ?? null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type PrusaIni } from "./ini.js";
|
|
2
|
+
export type OrcaSettings = Record<string, string | string[]>;
|
|
3
|
+
export interface ConvertedSettings {
|
|
4
|
+
settings: OrcaSettings;
|
|
5
|
+
/** Settings with no Snapmaker Orca counterpart, with the reason each wasn't carried. */
|
|
6
|
+
dropped: {
|
|
7
|
+
key: string;
|
|
8
|
+
why: string;
|
|
9
|
+
}[];
|
|
10
|
+
/** Keys this converter has no rule for (a newer PrusaSlicer); not carried. */
|
|
11
|
+
unknown: string[];
|
|
12
|
+
warnings: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An object's or a volume's own settings (PrusaSlicer keys, from the model config) in Snapmaker Orca's keys, one
|
|
16
|
+
* value each, for `model_settings.config`. A transform that reads other settings sees the project's, with the
|
|
17
|
+
* object's own over them. Keys with no single-value counterpart (filament settings, dropped keys) aren't carried.
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertObjectOverrides(ini: PrusaIni, overrides: ReadonlyMap<string, string>): Record<string, string>;
|
|
20
|
+
export declare function convertPrusaSettings(ini: PrusaIni): ConvertedSettings;
|