any2orca 0.0.0-stage → 0.1.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 +70 -0
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +99 -2
- package/dist/archive/adaptModelSettings.d.ts +1 -0
- package/dist/archive/adaptModelSettings.js +50 -0
- package/dist/archive/filamentColorNames.d.ts +8 -0
- package/dist/archive/filamentColorNames.js +760 -0
- package/dist/archive/fmtNum.d.ts +14 -0
- package/dist/archive/fmtNum.js +21 -0
- package/dist/archive/internal/escapeRegExp.d.ts +2 -0
- package/dist/archive/internal/escapeRegExp.js +5 -0
- package/dist/archive/lookupFilamentColorName.d.ts +45 -0
- package/dist/archive/lookupFilamentColorName.js +57 -0
- package/dist/archive/objectWorldBboxXY.d.ts +2 -0
- package/dist/archive/objectWorldBboxXY.js +123 -0
- package/dist/archive/parseItemPositions.d.ts +6 -0
- package/dist/archive/parseItemPositions.js +17 -0
- package/dist/archive/parseObjectMetadata.d.ts +10 -0
- package/dist/archive/parseObjectMetadata.js +97 -0
- package/dist/archive/parsePlateAssignments.d.ts +6 -0
- package/dist/archive/parsePlateAssignments.js +18 -0
- package/dist/archive/parseVertices.d.ts +7 -0
- package/dist/archive/parseVertices.js +12 -0
- package/dist/archive/paths.d.ts +5 -0
- package/dist/archive/paths.js +6 -0
- package/dist/archive/recenterAssembleItems.d.ts +9 -0
- package/dist/archive/recenterAssembleItems.js +53 -0
- package/dist/archive/recenterBuildItems.d.ts +15 -0
- package/dist/archive/recenterBuildItems.js +51 -0
- package/dist/archive/safeUnzip.d.ts +26 -0
- package/dist/archive/safeUnzip.js +126 -0
- package/dist/archive/setApplicationMetadata.d.ts +13 -0
- package/dist/archive/setApplicationMetadata.js +18 -0
- package/dist/archive/shouldDropFromBambu.d.ts +29 -0
- package/dist/archive/shouldDropFromBambu.js +39 -0
- package/dist/archive/streamObjectVertices.d.ts +19 -0
- package/dist/archive/streamObjectVertices.js +57 -0
- package/dist/archive/tolerantJsonParse.d.ts +20 -0
- package/dist/archive/tolerantJsonParse.js +71 -0
- package/dist/archive/transform.d.ts +21 -0
- package/dist/archive/transform.js +39 -0
- package/dist/archive/unwrapBundle.d.ts +24 -0
- package/dist/archive/unwrapBundle.js +41 -0
- package/dist/archive/xmlBlocks.d.ts +10 -0
- package/dist/archive/xmlBlocks.js +31 -0
- package/dist/archive/zip.d.ts +29 -0
- package/dist/archive/zip.js +141 -0
- package/dist/cli/archiveMove.d.ts +15 -0
- package/dist/cli/archiveMove.js +41 -0
- package/dist/cli/commands/convert.d.ts +89 -0
- package/dist/cli/commands/convert.js +311 -0
- package/dist/cli/commands/diff.d.ts +21 -0
- package/dist/cli/commands/diff.js +112 -0
- package/dist/cli/commands/presets.d.ts +51 -0
- package/dist/cli/commands/presets.js +280 -0
- package/dist/cli/commands/profiles.d.ts +5 -0
- package/dist/cli/commands/profiles.js +26 -0
- package/dist/cli/commands/telemetry.d.ts +6 -0
- package/dist/cli/commands/telemetry.js +45 -0
- package/dist/cli/config.d.ts +18 -0
- package/dist/cli/config.js +50 -0
- package/dist/cli/expandWildcards.d.ts +17 -0
- package/dist/cli/expandWildcards.js +81 -0
- package/dist/cli/logger.d.ts +17 -0
- package/dist/cli/logger.js +36 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/sameFile.d.ts +9 -0
- package/dist/cli/sameFile.js +40 -0
- package/dist/cli/stats.d.ts +34 -0
- package/dist/cli/stats.js +137 -0
- package/dist/cli/table.d.ts +8 -0
- package/dist/cli/table.js +18 -0
- package/dist/cli/terminalText.d.ts +7 -0
- package/dist/cli/terminalText.js +22 -0
- package/dist/cli/updateCheck.d.ts +14 -0
- package/dist/cli/updateCheck.js +78 -0
- package/dist/cli/watchState.d.ts +18 -0
- package/dist/cli/watchState.js +33 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +10 -0
- package/dist/diff/diffSettings.d.ts +81 -0
- package/dist/diff/diffSettings.js +259 -0
- package/dist/diff/reference.d.ts +14 -0
- package/dist/diff/reference.js +22 -0
- package/dist/diff/settingsCatalog.d.ts +28 -0
- package/dist/diff/settingsCatalog.js +605 -0
- package/dist/diff/valueLayout.d.ts +20 -0
- package/dist/diff/valueLayout.js +65 -0
- package/dist/engine/aboveStock.d.ts +20 -0
- package/dist/engine/aboveStock.js +89 -0
- package/dist/engine/applyFilamentComplianceMode.d.ts +40 -0
- package/dist/engine/applyFilamentComplianceMode.js +68 -0
- package/dist/engine/applyFilamentFlowVariants.d.ts +42 -0
- package/dist/engine/applyFilamentFlowVariants.js +109 -0
- package/dist/engine/applyHighFlowHotends.d.ts +52 -0
- package/dist/engine/applyHighFlowHotends.js +115 -0
- package/dist/engine/applyPresetChanges.d.ts +12 -0
- package/dist/engine/applyPresetChanges.js +23 -0
- package/dist/engine/bedCenter.d.ts +19 -0
- package/dist/engine/bedCenter.js +34 -0
- package/dist/engine/buildFilamentConfigs.d.ts +18 -0
- package/dist/engine/buildFilamentConfigs.js +49 -0
- package/dist/engine/buildProjectSettings.d.ts +24 -0
- package/dist/engine/buildProjectSettings.js +164 -0
- package/dist/engine/carrySourceLayerHeight.d.ts +15 -0
- package/dist/engine/carrySourceLayerHeight.js +41 -0
- package/dist/engine/clampColorPenetration.d.ts +12 -0
- package/dist/engine/clampColorPenetration.js +28 -0
- package/dist/engine/clampToMachineLimits.d.ts +21 -0
- package/dist/engine/clampToMachineLimits.js +84 -0
- package/dist/engine/coerceValue.d.ts +15 -0
- package/dist/engine/coerceValue.js +56 -0
- package/dist/engine/collapseNozzleVariants.d.ts +31 -0
- package/dist/engine/collapseNozzleVariants.js +63 -0
- package/dist/engine/computeShifts.d.ts +12 -0
- package/dist/engine/computeShifts.js +339 -0
- package/dist/engine/constants.d.ts +11 -0
- package/dist/engine/constants.js +12 -0
- package/dist/engine/detectNozzleDiameter.d.ts +15 -0
- package/dist/engine/detectNozzleDiameter.js +29 -0
- package/dist/engine/detectVariantIndex.d.ts +39 -0
- package/dist/engine/detectVariantIndex.js +80 -0
- package/dist/engine/extractFilamentSlots.d.ts +18 -0
- package/dist/engine/extractFilamentSlots.js +88 -0
- package/dist/engine/filamentComplianceNames.d.ts +84 -0
- package/dist/engine/filamentComplianceNames.js +87 -0
- package/dist/engine/filamentVariantLayout.d.ts +29 -0
- package/dist/engine/filamentVariantLayout.js +38 -0
- package/dist/engine/fillFilamentSlots.d.ts +16 -0
- package/dist/engine/fillFilamentSlots.js +26 -0
- package/dist/engine/internal/jsonEqual.d.ts +2 -0
- package/dist/engine/internal/jsonEqual.js +5 -0
- package/dist/engine/parseTierName.d.ts +15 -0
- package/dist/engine/parseTierName.js +21 -0
- package/dist/engine/pickNearestProfile.d.ts +21 -0
- package/dist/engine/pickNearestProfile.js +24 -0
- package/dist/engine/pickProfile.d.ts +49 -0
- package/dist/engine/pickProfile.js +67 -0
- package/dist/engine/policy.d.ts +14 -0
- package/dist/engine/policy.js +266 -0
- package/dist/engine/remapBrimType.d.ts +30 -0
- package/dist/engine/remapBrimType.js +34 -0
- package/dist/engine/reshapeToCount.d.ts +15 -0
- package/dist/engine/reshapeToCount.js +27 -0
- package/dist/engine/resizeFlushVolumes.d.ts +27 -0
- package/dist/engine/resizeFlushVolumes.js +57 -0
- package/dist/engine/resolveMinIfLower.d.ts +21 -0
- package/dist/engine/resolveMinIfLower.js +59 -0
- package/dist/engine/runConvertPipeline.d.ts +79 -0
- package/dist/engine/runConvertPipeline.js +281 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.d.ts +2 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.js +35 -0
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/types.js +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +9 -0
- package/dist/explain/whatChanged.d.ts +102 -0
- package/dist/explain/whatChanged.js +197 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +33 -0
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.js +103 -0
- package/dist/node.d.ts +11 -0
- package/dist/node.js +50 -0
- package/dist/plainText.d.ts +10 -0
- package/dist/plainText.js +14 -0
- package/dist/presets/extractPreset.d.ts +13 -0
- package/dist/presets/extractPreset.js +87 -0
- package/dist/presets/preset.d.ts +124 -0
- package/dist/presets/preset.js +289 -0
- package/dist/presets/presetKeys.d.ts +5 -0
- package/dist/presets/presetKeys.js +42 -0
- package/dist/profiles.d.ts +184 -0
- package/dist/profiles.js +314 -0
- package/dist/project.d.ts +146 -0
- package/dist/project.js +342 -0
- package/dist/schema.d.ts +103 -0
- package/dist/schema.js +87 -0
- package/dist/stamp.d.ts +45 -0
- package/dist/stamp.js +111 -0
- package/dist/telemetry.d.ts +101 -0
- package/dist/telemetry.js +94 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +142 -0
- package/dist/worker.d.ts +86 -0
- package/dist/worker.js +97 -0
- package/dist/workerProtocol.d.ts +91 -0
- package/dist/workerProtocol.js +1 -0
- package/package.json +85 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Print settings a two-nozzle source may store per nozzle and flow variant:
|
|
4
|
+
* the ones the U1 stores per variant, plus the two it stores as one value.
|
|
5
|
+
* An explicit list, because other project arrays (one entry per filament)
|
|
6
|
+
* can have the same length by coincidence.
|
|
7
|
+
*/
|
|
8
|
+
export declare const NOZZLE_VARIANT_KEYS: ReadonlySet<string>;
|
|
9
|
+
export interface CollapsedNozzleVariants {
|
|
10
|
+
/** The source settings with each per-nozzle key reduced to one value per flow variant. The input when it isn't a two-nozzle file. */
|
|
11
|
+
settings: JsonRecord;
|
|
12
|
+
/** Keys whose nozzles disagreed, with the source's original values; the lower value was used. */
|
|
13
|
+
conflicts: Map<string, unknown[]>;
|
|
14
|
+
/** The variant both nozzles have installed, as a column of the collapsed values, or null when they differ or it isn't a two-nozzle file. */
|
|
15
|
+
variantIndex: number | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Bambu's two-nozzle printers (H2D, H2C) store some print settings once per
|
|
19
|
+
* nozzle and flow variant: with `print_extruder_id` `["1","1","2","2"]` and
|
|
20
|
+
* `print_extruder_variant` `["Direct Drive Standard", "Direct Drive High
|
|
21
|
+
* Flow", ...]`, `outer_wall_speed` `["50","60","50","60"]` means 50 on a
|
|
22
|
+
* standard nozzle and 60 on a high-flow one, for both nozzles. Each such
|
|
23
|
+
* key becomes one value per variant, in nozzle 1's variant order: the
|
|
24
|
+
* `[standard, high_flow]` layout single-nozzle Bambu files and the U1 use.
|
|
25
|
+
*
|
|
26
|
+
* When the nozzles disagree on a variant, the lower number is used: the
|
|
27
|
+
* U1's four toolheads don't map onto the source's two nozzles, and the
|
|
28
|
+
* lower speed suits either. Values that aren't numbers take nozzle 1's.
|
|
29
|
+
* Either way the key is reported in `conflicts`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function collapseNozzleVariants(source: JsonRecord): CollapsedNozzleVariants;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { VARIANT_PROCESS_KEYS } from "./applyHighFlowHotends.js";
|
|
3
|
+
/**
|
|
4
|
+
* Print settings a two-nozzle source may store per nozzle and flow variant:
|
|
5
|
+
* the ones the U1 stores per variant, plus the two it stores as one value.
|
|
6
|
+
* An explicit list, because other project arrays (one entry per filament)
|
|
7
|
+
* can have the same length by coincidence.
|
|
8
|
+
*/
|
|
9
|
+
export const NOZZLE_VARIANT_KEYS = new Set([...VARIANT_PROCESS_KEYS, "top_solid_infill_flow_ratio", "travel_speed_z"]);
|
|
10
|
+
const asStrings = (value) => (Array.isArray(value) ? value.map((v) => String(v)) : null);
|
|
11
|
+
const normalize = (s) => s.replace(/\s+/g, "").toLowerCase();
|
|
12
|
+
/**
|
|
13
|
+
* Bambu's two-nozzle printers (H2D, H2C) store some print settings once per
|
|
14
|
+
* nozzle and flow variant: with `print_extruder_id` `["1","1","2","2"]` and
|
|
15
|
+
* `print_extruder_variant` `["Direct Drive Standard", "Direct Drive High
|
|
16
|
+
* Flow", ...]`, `outer_wall_speed` `["50","60","50","60"]` means 50 on a
|
|
17
|
+
* standard nozzle and 60 on a high-flow one, for both nozzles. Each such
|
|
18
|
+
* key becomes one value per variant, in nozzle 1's variant order: the
|
|
19
|
+
* `[standard, high_flow]` layout single-nozzle Bambu files and the U1 use.
|
|
20
|
+
*
|
|
21
|
+
* When the nozzles disagree on a variant, the lower number is used: the
|
|
22
|
+
* U1's four toolheads don't map onto the source's two nozzles, and the
|
|
23
|
+
* lower speed suits either. Values that aren't numbers take nozzle 1's.
|
|
24
|
+
* Either way the key is reported in `conflicts`.
|
|
25
|
+
*/
|
|
26
|
+
export function collapseNozzleVariants(source) {
|
|
27
|
+
const unchanged = { settings: source, conflicts: new Map(), variantIndex: null };
|
|
28
|
+
const ids = asStrings(source.print_extruder_id);
|
|
29
|
+
const variants = asStrings(source.print_extruder_variant);
|
|
30
|
+
if (!ids || !variants || ids.length !== variants.length || new Set(ids).size < 2)
|
|
31
|
+
return unchanged;
|
|
32
|
+
// Column order of the result: nozzle 1's variants, standard before high flow as the U1 stores them. Every nozzle must have exactly those, once each.
|
|
33
|
+
const nozzles = [...new Set(ids)];
|
|
34
|
+
const isHighFlow = (variant) => (normalize(variant).includes("highflow") ? 1 : 0);
|
|
35
|
+
const order = variants.filter((_, i) => ids[i] === nozzles[0]).sort((a, b) => isHighFlow(a) - isHighFlow(b));
|
|
36
|
+
const columnOf = new Map(); // "nozzle|variant" -> source column
|
|
37
|
+
ids.forEach((id, i) => columnOf.set(`${id}|${variants[i]}`, i));
|
|
38
|
+
if (columnOf.size !== ids.length || nozzles.some((n) => order.some((v) => !columnOf.has(`${n}|${v}`))))
|
|
39
|
+
return unchanged;
|
|
40
|
+
const settings = { ...source };
|
|
41
|
+
const conflicts = new Map();
|
|
42
|
+
for (const key of NOZZLE_VARIANT_KEYS) {
|
|
43
|
+
const value = source[key];
|
|
44
|
+
if (!Array.isArray(value) || value.length !== ids.length)
|
|
45
|
+
continue;
|
|
46
|
+
let disagreed = false;
|
|
47
|
+
settings[key] = order.map((variant) => {
|
|
48
|
+
const values = nozzles.map((n) => value[columnOf.get(`${n}|${variant}`)]);
|
|
49
|
+
if (values.every((v) => String(v) === String(values[0])))
|
|
50
|
+
return values[0];
|
|
51
|
+
disagreed = true;
|
|
52
|
+
const numbers = values.map((v) => Number(v));
|
|
53
|
+
return numbers.every((n) => Number.isFinite(n)) ? values[numbers.indexOf(Math.min(...numbers))] : values[0];
|
|
54
|
+
});
|
|
55
|
+
if (disagreed)
|
|
56
|
+
conflicts.set(key, value);
|
|
57
|
+
}
|
|
58
|
+
// The variant actually installed, when both nozzles have the same one ("Standard" in nozzle_volume_type, "Direct Drive Standard" in the variant names).
|
|
59
|
+
const installed = asStrings(source.nozzle_volume_type);
|
|
60
|
+
const shared = installed && installed.length > 0 && installed.every((v) => normalize(v) === normalize(installed[0])) ? normalize(installed[0]) : null;
|
|
61
|
+
const index = shared ? order.findIndex((v) => normalize(v).endsWith(shared)) : -1;
|
|
62
|
+
return { settings, conflicts, variantIndex: index >= 0 ? index : null };
|
|
63
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConvertObject } from "../schema.js";
|
|
2
|
+
export interface ComputeShiftsResult {
|
|
3
|
+
shifts: Record<string, [number, number]>;
|
|
4
|
+
warnings: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The grid-layout, pitch and clearance-scaling step. Takes each object's
|
|
8
|
+
* *already computed* world-space bounding box (from the request's
|
|
9
|
+
* `objects[]`) instead of deriving it from mesh geometry, so the mesh is
|
|
10
|
+
* read only once, when the file is opened.
|
|
11
|
+
*/
|
|
12
|
+
export declare function computeShifts(objects: readonly ConvertObject[], orcaPrintableArea: readonly string[], bambuClearanceRadius: number | null, orcaClearanceRadius: number | null): ComputeShiftsResult;
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { parseBedCorners } from "./bedCenter.js";
|
|
2
|
+
// Below this, two AABBs count as "touching" for the shrink-to-fit pass's
|
|
3
|
+
// warning -- deliberately not zero: a small margin catches genuinely-tight
|
|
4
|
+
// arrangements without crying wolf over boxes that technically clear each
|
|
5
|
+
// other by a fraction of a mm (this checks *bounding boxes*, not the actual
|
|
6
|
+
// mesh, so some slack is honest about that imprecision).
|
|
7
|
+
const TOUCHING_TOLERANCE_MM = 2;
|
|
8
|
+
// Kept clear of the true bed edge on every side when fitting/shrinking a
|
|
9
|
+
// plate -- confirmed necessary directly: without this, an object could
|
|
10
|
+
// land exactly on the boundary (a mathematically valid fit), which still
|
|
11
|
+
// got flagged by Orca's own slicing check as sitting right on the edge.
|
|
12
|
+
// Orca's own check turned out to require >=3.5mm; padded up from there
|
|
13
|
+
// rather than shaving it exactly, so a small amount of slop (rounding,
|
|
14
|
+
// slightly different geometry) doesn't reopen the same complaint.
|
|
15
|
+
const EDGE_MARGIN_MM = 5;
|
|
16
|
+
/** True Euclidean gap between two axis-aligned boxes; 0 or negative means they touch or overlap. */
|
|
17
|
+
function aabbGap(a, b) {
|
|
18
|
+
const [aMinX, aMaxX, aMinY, aMaxY] = a;
|
|
19
|
+
const [bMinX, bMaxX, bMinY, bMaxY] = b;
|
|
20
|
+
const xGap = Math.max(bMinX - aMaxX, aMinX - bMaxX);
|
|
21
|
+
const yGap = Math.max(bMinY - aMaxY, aMinY - bMaxY);
|
|
22
|
+
if (xGap <= 0 && yGap <= 0)
|
|
23
|
+
return Math.max(xGap, yGap); // overlapping on both axes
|
|
24
|
+
if (xGap <= 0)
|
|
25
|
+
return yGap; // overlap in X, separated in Y -- pure Y gap
|
|
26
|
+
if (yGap <= 0)
|
|
27
|
+
return xGap; // overlap in Y, separated in X -- pure X gap
|
|
28
|
+
return Math.sqrt(xGap * xGap + yGap * yGap); // diagonal case
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The grid-layout, pitch and clearance-scaling step. Takes each object's
|
|
32
|
+
* *already computed* world-space bounding box (from the request's
|
|
33
|
+
* `objects[]`) instead of deriving it from mesh geometry, so the mesh is
|
|
34
|
+
* read only once, when the file is opened.
|
|
35
|
+
*/
|
|
36
|
+
export function computeShifts(objects, orcaPrintableArea, bambuClearanceRadius, orcaClearanceRadius) {
|
|
37
|
+
const warnings = [];
|
|
38
|
+
const objectById = new Map(objects.map((o) => [o.id, o]));
|
|
39
|
+
// Group object ids by plate; objects with no plate metadata each become
|
|
40
|
+
// their own singleton "unassigned" group.
|
|
41
|
+
const plateGroups = new Map();
|
|
42
|
+
const unassignedIds = [];
|
|
43
|
+
for (const obj of objects) {
|
|
44
|
+
if (obj.plate !== undefined) {
|
|
45
|
+
const arr = plateGroups.get(obj.plate) ?? [];
|
|
46
|
+
arr.push(obj.id);
|
|
47
|
+
plateGroups.set(obj.plate, arr);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
unassignedIds.push(obj.id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const plateKeys = [...plateGroups.keys()].sort((a, b) => a - b);
|
|
54
|
+
// Each plate's TRUE combined geometric bbox center, plus each individual
|
|
55
|
+
// object's own bbox (needed by the clearance-scaling pass below).
|
|
56
|
+
const objectBbox = new Map();
|
|
57
|
+
const groupCenter = new Map();
|
|
58
|
+
const computeGroupCenter = (oids) => {
|
|
59
|
+
let xsMin = Infinity;
|
|
60
|
+
let xsMax = -Infinity;
|
|
61
|
+
let ysMin = Infinity;
|
|
62
|
+
let ysMax = -Infinity;
|
|
63
|
+
let found = false;
|
|
64
|
+
for (const oid of oids) {
|
|
65
|
+
const bbox = objectById.get(oid)?.bbox;
|
|
66
|
+
if (!bbox)
|
|
67
|
+
continue;
|
|
68
|
+
const [minX, maxX, minY, maxY] = bbox;
|
|
69
|
+
objectBbox.set(oid, bbox);
|
|
70
|
+
xsMin = Math.min(xsMin, minX);
|
|
71
|
+
xsMax = Math.max(xsMax, maxX);
|
|
72
|
+
ysMin = Math.min(ysMin, minY);
|
|
73
|
+
ysMax = Math.max(ysMax, maxY);
|
|
74
|
+
found = true;
|
|
75
|
+
}
|
|
76
|
+
if (found) {
|
|
77
|
+
return [(xsMin + xsMax) / 2, (ysMin + ysMax) / 2];
|
|
78
|
+
}
|
|
79
|
+
const fallback = objectById.get(oids[0])?.fallbackXy;
|
|
80
|
+
if (!fallback) {
|
|
81
|
+
warnings.push(` WARN: object ${oids[0]} has no bbox and no fallback_xy; treating its position as (0, 0).`);
|
|
82
|
+
return [0, 0];
|
|
83
|
+
}
|
|
84
|
+
return fallback;
|
|
85
|
+
};
|
|
86
|
+
for (const key of plateKeys) {
|
|
87
|
+
groupCenter.set(key, computeGroupCenter(plateGroups.get(key)));
|
|
88
|
+
}
|
|
89
|
+
for (const oid of unassignedIds) {
|
|
90
|
+
groupCenter.set(`__unassigned_${oid}`, computeGroupCenter([oid]));
|
|
91
|
+
}
|
|
92
|
+
// Bambu and Orca each arrange multiple plates in a roughly square grid
|
|
93
|
+
// (columns = ceil(sqrt(plate count)), row-major), and each computes its
|
|
94
|
+
// own pitch from its OWN bed size, not the source file's spacing (Orca's
|
|
95
|
+
// own "Center" operation on the U1's 270mm bed uses 270*1.2 = 324mm
|
|
96
|
+
// spacing, confirmed against real before/after coordinates).
|
|
97
|
+
const cols = plateKeys.length > 0 ? Math.max(1, Math.ceil(Math.sqrt(plateKeys.length))) : 1;
|
|
98
|
+
const orcaBed = parseBedCorners(orcaPrintableArea);
|
|
99
|
+
const orcaBedW = orcaBed.maxX - orcaBed.minX;
|
|
100
|
+
const orcaBedH = orcaBed.maxY - orcaBed.minY;
|
|
101
|
+
const pitchX = orcaBedW * 1.2;
|
|
102
|
+
const pitchY = -orcaBedH * 1.2;
|
|
103
|
+
const [orcaCx, orcaCy] = [orcaBed.centerX, orcaBed.centerY];
|
|
104
|
+
// The fit/shrink math below targets this slightly-smaller "usable" area
|
|
105
|
+
// (inset by EDGE_MARGIN_MM on every side), not the raw bed -- pitch/grid
|
|
106
|
+
// layout above is unaffected, this only matters for how close a single
|
|
107
|
+
// plate's own objects are allowed to sit to the true edge.
|
|
108
|
+
const usableBedW = Math.max(0, orcaBedW - 2 * EDGE_MARGIN_MM);
|
|
109
|
+
const usableBedH = Math.max(0, orcaBedH - 2 * EDGE_MARGIN_MM);
|
|
110
|
+
const shifts = {};
|
|
111
|
+
const groupTarget = new Map();
|
|
112
|
+
const groupOids = new Map();
|
|
113
|
+
const applyGroupShift = (key, oids, target) => {
|
|
114
|
+
groupTarget.set(key, target);
|
|
115
|
+
groupOids.set(key, oids);
|
|
116
|
+
const [bboxCx, bboxCy] = groupCenter.get(key);
|
|
117
|
+
const dx = target[0] - bboxCx;
|
|
118
|
+
const dy = target[1] - bboxCy;
|
|
119
|
+
const label = typeof key === "number" ? `plate ${key}` : `object ${oids[0]} (no plate metadata)`;
|
|
120
|
+
warnings.push(` ${label}: true geometric center (${bboxCx.toFixed(2)}, ${bboxCy.toFixed(2)}) -> ` +
|
|
121
|
+
`target (${target[0].toFixed(2)}, ${target[1].toFixed(2)}), shift (${dx >= 0 ? "+" : ""}${dx.toFixed(2)}, ${dy >= 0 ? "+" : ""}${dy.toFixed(2)}) mm`);
|
|
122
|
+
for (const oid of oids) {
|
|
123
|
+
shifts[oid] = [dx, dy];
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
plateKeys.forEach((key, plateIdx) => {
|
|
127
|
+
const col = plateIdx % cols;
|
|
128
|
+
const row = Math.floor(plateIdx / cols);
|
|
129
|
+
applyGroupShift(key, plateGroups.get(key), [orcaCx + col * pitchX, orcaCy + row * pitchY]);
|
|
130
|
+
});
|
|
131
|
+
for (const oid of unassignedIds) {
|
|
132
|
+
applyGroupShift(`__unassigned_${oid}`, [oid], [orcaCx, orcaCy]);
|
|
133
|
+
}
|
|
134
|
+
// ---- Spacing-scale pass ----
|
|
135
|
+
// Scales each multi-object plate's arrangement around its own true-
|
|
136
|
+
// geometry centroid -- outward (grow) restores the same proportional
|
|
137
|
+
// safety margin the layout had under Bambu's smaller clearance radius
|
|
138
|
+
// (proportional scaling, rather than reimplementing Orca's exact collision
|
|
139
|
+
// geometry); inward (shrink)
|
|
140
|
+
// is the opposite move, used when the plate doesn't even fit the target
|
|
141
|
+
// bed at its original spacing -- translation alone can't fix that
|
|
142
|
+
// without silently rescaling the creator's own geometry, but pulling
|
|
143
|
+
// objects closer together (never resizing them) can. Growing is capped
|
|
144
|
+
// at whatever fits the bed; shrinking is only ever as tight as the bed
|
|
145
|
+
// actually requires, and flagged if that leaves objects touching.
|
|
146
|
+
const desiredRatio = bambuClearanceRadius && orcaClearanceRadius && orcaClearanceRadius > bambuClearanceRadius
|
|
147
|
+
? orcaClearanceRadius / bambuClearanceRadius
|
|
148
|
+
: 1.0;
|
|
149
|
+
const shrunkPlates = new Set();
|
|
150
|
+
for (const key of plateKeys) {
|
|
151
|
+
const oids = (plateGroups.get(key) ?? []).filter((oid) => objectBbox.has(oid));
|
|
152
|
+
if (oids.length < 2)
|
|
153
|
+
continue; // nothing to space apart or compact on a single-object plate
|
|
154
|
+
const centroid = groupCenter.get(key);
|
|
155
|
+
// Windows each plate around its own grid target rather than the bed's
|
|
156
|
+
// absolute bounds -- mathematically equivalent to using the absolute
|
|
157
|
+
// bounds directly (both reduce to the same distance-to-half-bed-width
|
|
158
|
+
// check, since the bed is always symmetric around its own center), but
|
|
159
|
+
// explicit rather than relying on that coincidence, and reads
|
|
160
|
+
// correctly at a glance for plates beyond the first. Sized to the
|
|
161
|
+
// usable (margin-inset) area, not the raw bed -- see EDGE_MARGIN_MM.
|
|
162
|
+
const [targetX, targetY] = groupTarget.get(key);
|
|
163
|
+
const winMinX = targetX - usableBedW / 2;
|
|
164
|
+
const winMaxX = targetX + usableBedW / 2;
|
|
165
|
+
const winMinY = targetY - usableBedH / 2;
|
|
166
|
+
const winMaxY = targetY + usableBedH / 2;
|
|
167
|
+
let effectiveRatio = desiredRatio;
|
|
168
|
+
for (const oid of oids) {
|
|
169
|
+
const [minX, maxX, minY, maxY] = objectBbox.get(oid);
|
|
170
|
+
const ocx = (minX + maxX) / 2;
|
|
171
|
+
const ocy = (minY + maxY) / 2;
|
|
172
|
+
const halfW = (maxX - minX) / 2;
|
|
173
|
+
const halfH = (maxY - minY) / 2;
|
|
174
|
+
const vx = ocx - centroid[0];
|
|
175
|
+
const vy = ocy - centroid[1];
|
|
176
|
+
for (const [v, half, base, lo, hi] of [
|
|
177
|
+
[vx, halfW, targetX, winMinX, winMaxX],
|
|
178
|
+
[vy, halfH, targetY, winMinY, winMaxY],
|
|
179
|
+
]) {
|
|
180
|
+
if (v > 1e-9) {
|
|
181
|
+
effectiveRatio = Math.min(effectiveRatio, (hi - half - base) / v);
|
|
182
|
+
}
|
|
183
|
+
else if (v < -1e-9) {
|
|
184
|
+
effectiveRatio = Math.min(effectiveRatio, (lo + half - base) / v);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// No lower floor at 1.0 here (unlike the grow-only version this
|
|
189
|
+
// replaced) -- that's precisely what lets this shrink below 1 when the
|
|
190
|
+
// plate doesn't fit the bed even at its original spacing. Floored at 0
|
|
191
|
+
// instead: a negative ratio would flip objects to the opposite side of
|
|
192
|
+
// the centroid, which is never useful -- 0 is "collapse onto the
|
|
193
|
+
// centroid point," the tightest this pass can ever get.
|
|
194
|
+
effectiveRatio = Math.max(0, effectiveRatio);
|
|
195
|
+
// Pulling objects together never makes two of them overlap that didn't before: Snapmaker Orca refuses to
|
|
196
|
+
// slice such a plate. The gap between two boxes only grows with the ratio, so the tightest ratio that keeps
|
|
197
|
+
// every such pair apart is found by bisection; a plate still too big then gets the footprint warning below.
|
|
198
|
+
if (effectiveRatio < 1) {
|
|
199
|
+
const scaledBox = (oid, r) => {
|
|
200
|
+
const [minX, maxX, minY, maxY] = objectBbox.get(oid);
|
|
201
|
+
const dx = (r - 1) * ((minX + maxX) / 2 - centroid[0]);
|
|
202
|
+
const dy = (r - 1) * ((minY + maxY) / 2 - centroid[1]);
|
|
203
|
+
return [minX + dx, maxX + dx, minY + dy, maxY + dy];
|
|
204
|
+
};
|
|
205
|
+
const apartAtStart = [];
|
|
206
|
+
for (let i = 0; i < oids.length; i++) {
|
|
207
|
+
for (let j = i + 1; j < oids.length; j++) {
|
|
208
|
+
if (aabbGap(objectBbox.get(oids[i]), objectBbox.get(oids[j])) > 0)
|
|
209
|
+
apartAtStart.push([oids[i], oids[j]]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const keepsApart = (r) => apartAtStart.every(([a, b]) => aabbGap(scaledBox(a, r), scaledBox(b, r)) > 0);
|
|
213
|
+
if (!keepsApart(effectiveRatio)) {
|
|
214
|
+
let lo = effectiveRatio;
|
|
215
|
+
let hi = 1;
|
|
216
|
+
for (let step = 0; step < 40; step++) {
|
|
217
|
+
const mid = (lo + hi) / 2;
|
|
218
|
+
if (keepsApart(mid))
|
|
219
|
+
hi = mid;
|
|
220
|
+
else
|
|
221
|
+
lo = mid;
|
|
222
|
+
}
|
|
223
|
+
effectiveRatio = hi;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (Math.abs(effectiveRatio - 1) > 1e-4) {
|
|
227
|
+
for (const oid of oids) {
|
|
228
|
+
const [minX, maxX, minY, maxY] = objectBbox.get(oid);
|
|
229
|
+
const ocx = (minX + maxX) / 2;
|
|
230
|
+
const ocy = (minY + maxY) / 2;
|
|
231
|
+
const extraDx = (effectiveRatio - 1) * (ocx - centroid[0]);
|
|
232
|
+
const extraDy = (effectiveRatio - 1) * (ocy - centroid[1]);
|
|
233
|
+
const [oldDx, oldDy] = shifts[oid];
|
|
234
|
+
shifts[oid] = [oldDx + extraDx, oldDy + extraDy];
|
|
235
|
+
}
|
|
236
|
+
if (effectiveRatio > 1) {
|
|
237
|
+
const wasClamped = effectiveRatio < desiredRatio - 1e-6;
|
|
238
|
+
warnings.push(` plate ${key}: spacing scaled ${effectiveRatio.toFixed(4)}x around its centroid ` +
|
|
239
|
+
`(clearance radius ${bambuClearanceRadius}mm -> ${orcaClearanceRadius}mm)${wasClamped ? "; clamped, see below" : ""}`);
|
|
240
|
+
// Routine (unclamped) scaling is informational only -- not worth
|
|
241
|
+
// surfacing to the end user. Being clamped means the ideal scale
|
|
242
|
+
// didn't fit and objects may now sit closer together than the
|
|
243
|
+
// U1's own clearance radius calls for; that genuinely needs a
|
|
244
|
+
// human's attention, so it gets its own "WARN:"-prefixed entry
|
|
245
|
+
// (the marker callers filter user-facing warnings on, matching
|
|
246
|
+
// every other actionable warning in this pipeline).
|
|
247
|
+
if (wasClamped) {
|
|
248
|
+
warnings.push(` WARN: plate ${key}'s spacing was clamped to ${effectiveRatio.toFixed(4)}x (ideally ${desiredRatio.toFixed(4)}x) ` +
|
|
249
|
+
`to keep every object on the bed, so objects on this plate may be closer together than the Snapmaker U1's ` +
|
|
250
|
+
`clearance radius calls for. Review spacing on this plate manually before printing.`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
shrunkPlates.add(key);
|
|
255
|
+
warnings.push(` plate ${key}: spacing tightened to ${effectiveRatio.toFixed(4)}x around its centroid to fit the ` +
|
|
256
|
+
`target bed (${orcaBedW.toFixed(1)} x ${orcaBedH.toFixed(1)} mm, keeping a ${EDGE_MARGIN_MM}mm margin from the edge); ` +
|
|
257
|
+
`see below for whether that leaves objects touching.`);
|
|
258
|
+
// Shrinking never fails to fit the bed by construction (it's
|
|
259
|
+
// solved for exactly that), but pulling objects closer together
|
|
260
|
+
// can leave them touching or overlapping -- that's the thing
|
|
261
|
+
// worth a human's attention here, checked below using final
|
|
262
|
+
// (post-shift) positions across every group, not just this one.
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// ---- Final bed-fit check ----
|
|
267
|
+
// Runs after any grow/shrink above, using each object's FINAL (fully
|
|
268
|
+
// shifted) position -- not the pre-scale footprint -- since shrinking
|
|
269
|
+
// can resolve an overflow that would otherwise still be there. Confirmed
|
|
270
|
+
// real-world trigger: converting from a printer with a larger bed than
|
|
271
|
+
// the target (e.g. Bambu H2C's 330x320mm vs the U1's 270x270mm) with a
|
|
272
|
+
// plate whose spacing can't be tightened enough to fit (rare -- most
|
|
273
|
+
// real layouts have some slack -- but possible if objects are already
|
|
274
|
+
// packed edge-to-edge).
|
|
275
|
+
for (const [key, oids] of groupOids) {
|
|
276
|
+
let xsMin = Infinity;
|
|
277
|
+
let xsMax = -Infinity;
|
|
278
|
+
let ysMin = Infinity;
|
|
279
|
+
let ysMax = -Infinity;
|
|
280
|
+
let found = false;
|
|
281
|
+
for (const oid of oids) {
|
|
282
|
+
const bbox = objectBbox.get(oid);
|
|
283
|
+
if (!bbox)
|
|
284
|
+
continue;
|
|
285
|
+
const [dx, dy] = shifts[oid];
|
|
286
|
+
xsMin = Math.min(xsMin, bbox[0] + dx);
|
|
287
|
+
xsMax = Math.max(xsMax, bbox[1] + dx);
|
|
288
|
+
ysMin = Math.min(ysMin, bbox[2] + dy);
|
|
289
|
+
ysMax = Math.max(ysMax, bbox[3] + dy);
|
|
290
|
+
found = true;
|
|
291
|
+
}
|
|
292
|
+
if (!found)
|
|
293
|
+
continue; // fallback_xy-only group -- a point, nothing to check
|
|
294
|
+
const footprintW = xsMax - xsMin;
|
|
295
|
+
const footprintH = ysMax - ysMin;
|
|
296
|
+
const overW = footprintW - usableBedW;
|
|
297
|
+
const overH = footprintH - usableBedH;
|
|
298
|
+
if (overW > 1e-6 || overH > 1e-6) {
|
|
299
|
+
const label = typeof key === "number" ? `plate ${key}` : `object ${oids[0]} (no plate metadata)`;
|
|
300
|
+
warnings.push(` WARN: ${label}'s combined footprint (${footprintW.toFixed(1)} x ${footprintH.toFixed(1)} mm) is larger ` +
|
|
301
|
+
`than the usable printable area (${usableBedW.toFixed(1)} x ${usableBedH.toFixed(1)} mm, keeping a ${EDGE_MARGIN_MM}mm ` +
|
|
302
|
+
`margin from the ${orcaBedW.toFixed(1)} x ${orcaBedH.toFixed(1)} mm bed's edge)${overW > 1e-6 ? ` by ${overW.toFixed(1)}mm in X` : ""}${overW > 1e-6 && overH > 1e-6 ? " and" : ""}${overH > 1e-6 ? ` by ${overH.toFixed(1)}mm in Y` : ""} -- ` +
|
|
303
|
+
`some objects will be positioned outside the printable area even when centered. Split this plate or rearrange/scale down the objects before converting.`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// ---- Touching check (only for plates that were actively shrunk) ----
|
|
307
|
+
for (const key of plateKeys) {
|
|
308
|
+
if (!shrunkPlates.has(key))
|
|
309
|
+
continue;
|
|
310
|
+
const oids = (plateGroups.get(key) ?? []).filter((oid) => objectBbox.has(oid));
|
|
311
|
+
if (oids.length < 2)
|
|
312
|
+
continue;
|
|
313
|
+
let closestGap = Infinity;
|
|
314
|
+
let closestPair = null;
|
|
315
|
+
for (let i = 0; i < oids.length; i++) {
|
|
316
|
+
for (let j = i + 1; j < oids.length; j++) {
|
|
317
|
+
const [oidA, oidB] = [oids[i], oids[j]];
|
|
318
|
+
const [dxA, dyA] = shifts[oidA];
|
|
319
|
+
const [dxB, dyB] = shifts[oidB];
|
|
320
|
+
const bboxA = objectBbox.get(oidA);
|
|
321
|
+
const bboxB = objectBbox.get(oidB);
|
|
322
|
+
const finalA = [bboxA[0] + dxA, bboxA[1] + dxA, bboxA[2] + dyA, bboxA[3] + dyA];
|
|
323
|
+
const finalB = [bboxB[0] + dxB, bboxB[1] + dxB, bboxB[2] + dyB, bboxB[3] + dyB];
|
|
324
|
+
const gap = aabbGap(finalA, finalB);
|
|
325
|
+
if (gap < closestGap) {
|
|
326
|
+
closestGap = gap;
|
|
327
|
+
closestPair = [oidA, oidB];
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (closestPair && closestGap < TOUCHING_TOLERANCE_MM) {
|
|
332
|
+
const gapDescription = closestGap <= 0 ? "are touching or overlapping" : `are only ${closestGap.toFixed(1)}mm apart`;
|
|
333
|
+
warnings.push(` WARN: plate ${key}'s objects were pulled together to fit the target bed, and object ${closestPair[0]} and ` +
|
|
334
|
+
`object ${closestPair[1]} ${gapDescription} as a result (tolerance ${TOUCHING_TOLERANCE_MM}mm). ` +
|
|
335
|
+
`Review spacing on this plate before printing.`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return { shifts, warnings };
|
|
339
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys inside project_settings.config that describe the per-filament-slot
|
|
3
|
+
* array but aren't part of the standalone filament_settings_N.config
|
|
4
|
+
* shape (which only holds settings for a single filament).
|
|
5
|
+
*
|
|
6
|
+
* Unlike `BLOCKLIST`/`U1_VALUE_KEYS`/`FILAMENT_KEY_BLOCKLIST`, this is a
|
|
7
|
+
* structural fact about the Bambu/Orca settings schema, not per-profile
|
|
8
|
+
* tuning data -- it doesn't vary by printer/profile, so it is a fixed
|
|
9
|
+
* engine constant rather than profile data.
|
|
10
|
+
*/
|
|
11
|
+
export declare const EXTRA_PROJECT_LEVEL_FILAMENT_KEYS: ReadonlySet<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Keys inside project_settings.config that describe the per-filament-slot
|
|
4
|
+
* array but aren't part of the standalone filament_settings_N.config
|
|
5
|
+
* shape (which only holds settings for a single filament).
|
|
6
|
+
*
|
|
7
|
+
* Unlike `BLOCKLIST`/`U1_VALUE_KEYS`/`FILAMENT_KEY_BLOCKLIST`, this is a
|
|
8
|
+
* structural fact about the Bambu/Orca settings schema, not per-profile
|
|
9
|
+
* tuning data -- it doesn't vary by printer/profile, so it is a fixed
|
|
10
|
+
* engine constant rather than profile data.
|
|
11
|
+
*/
|
|
12
|
+
export const EXTRA_PROJECT_LEVEL_FILAMENT_KEYS = new Set(["filament_colour", "filament_ids"]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/** Nozzle diameters we carry a Snapmaker U1 profile for, smallest first. */
|
|
3
|
+
export declare const SUPPORTED_NOZZLE_DIAMETERS: readonly ["0.2", "0.4", "0.6", "0.8"];
|
|
4
|
+
export type SupportedNozzleDiameter = (typeof SUPPORTED_NOZZLE_DIAMETERS)[number];
|
|
5
|
+
/**
|
|
6
|
+
* Reads the Bambu source's own `nozzle_diameter` (blocklisted from the
|
|
7
|
+
* merge itself, but still present in the raw uploaded project settings)
|
|
8
|
+
* and snaps it to the nearest U1 nozzle size we carry a profile for.
|
|
9
|
+
*
|
|
10
|
+
* Bambu stores this as a per-extruder array (e.g. `["0.4","0.4","0.4","0.4"]`)
|
|
11
|
+
* but a bare scalar is accepted too. Returns `null` when the value is
|
|
12
|
+
* missing or unparseable so the caller can fall back to the default
|
|
13
|
+
* profile rather than guess.
|
|
14
|
+
*/
|
|
15
|
+
export declare function detectNozzleDiameter(projectSettings: JsonRecord): SupportedNozzleDiameter | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Nozzle diameters we carry a Snapmaker U1 profile for, smallest first. */
|
|
2
|
+
export const SUPPORTED_NOZZLE_DIAMETERS = ["0.2", "0.4", "0.6", "0.8"];
|
|
3
|
+
/**
|
|
4
|
+
* Reads the Bambu source's own `nozzle_diameter` (blocklisted from the
|
|
5
|
+
* merge itself, but still present in the raw uploaded project settings)
|
|
6
|
+
* and snaps it to the nearest U1 nozzle size we carry a profile for.
|
|
7
|
+
*
|
|
8
|
+
* Bambu stores this as a per-extruder array (e.g. `["0.4","0.4","0.4","0.4"]`)
|
|
9
|
+
* but a bare scalar is accepted too. Returns `null` when the value is
|
|
10
|
+
* missing or unparseable so the caller can fall back to the default
|
|
11
|
+
* profile rather than guess.
|
|
12
|
+
*/
|
|
13
|
+
export function detectNozzleDiameter(projectSettings) {
|
|
14
|
+
const raw = projectSettings.nozzle_diameter;
|
|
15
|
+
const first = Array.isArray(raw) ? raw[0] : raw;
|
|
16
|
+
const value = typeof first === "string" ? Number.parseFloat(first) : typeof first === "number" ? first : NaN;
|
|
17
|
+
if (!Number.isFinite(value))
|
|
18
|
+
return null;
|
|
19
|
+
let closest = SUPPORTED_NOZZLE_DIAMETERS[0];
|
|
20
|
+
let closestDistance = Math.abs(value - Number.parseFloat(closest));
|
|
21
|
+
for (const candidate of SUPPORTED_NOZZLE_DIAMETERS) {
|
|
22
|
+
const distance = Math.abs(value - Number.parseFloat(candidate));
|
|
23
|
+
if (distance < closestDistance) {
|
|
24
|
+
closest = candidate;
|
|
25
|
+
closestDistance = distance;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return closest;
|
|
29
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Determines which column of Bambu's newer per-nozzle-variant paired
|
|
4
|
+
* arrays (e.g. `outer_wall_speed: ["210", "350"]`) reflects the settings
|
|
5
|
+
* Bambu Studio actually sliced with.
|
|
6
|
+
*
|
|
7
|
+
* Bambu Lab's newer hardened-steel nozzles support two flow profiles,
|
|
8
|
+
* "Standard" and "High Flow" -- and several process-level settings then
|
|
9
|
+
* carry one value per variant instead of a single scalar, even on
|
|
10
|
+
* printers with only ONE physical nozzle. The authoritative signal for
|
|
11
|
+
* which one was actually active is `nozzle_volume_type` (or
|
|
12
|
+
* `default_nozzle_volume_type`) -- e.g. `["Standard"]`. Confirmed against
|
|
13
|
+
* a real X1 Carbon export (single nozzle, `single_extruder_multi_material:
|
|
14
|
+
* 1`) that had `nozzle_volume_type: ["Standard"]` while the SELECTED
|
|
15
|
+
* FILAMENT PRESET was still named "... HF" (e.g. "Bambu PETG HF @BBL
|
|
16
|
+
* X1C") -- an initial version of this function used that filament-name
|
|
17
|
+
* "HF" substring as the signal instead, which is wrong: an "HF"-tuned
|
|
18
|
+
* filament preset can still be sliced with the Standard nozzle installed,
|
|
19
|
+
* and Bambu Studio then uses the Standard column regardless of the
|
|
20
|
+
* filament preset's own name.
|
|
21
|
+
*
|
|
22
|
+
* This is unrelated to genuine dual-physical-nozzle printers like the
|
|
23
|
+
* H2D -- deliberately scoped to single-physical-nozzle sources only (see
|
|
24
|
+
* the `nozzle_diameter` length check below), since a real multi-nozzle
|
|
25
|
+
* file might reuse these same field names for a different purpose (which
|
|
26
|
+
* physical nozzle a filament is assigned to), and that hasn't been
|
|
27
|
+
* verified, so this heuristic stays out of its way rather than guess.
|
|
28
|
+
*
|
|
29
|
+
* @returns the column index Bambu Studio actually used, or `null` when no
|
|
30
|
+
* usable signal is present -- callers should fall back to their
|
|
31
|
+
* existing "can't determine, ask for manual review" behavior in that case.
|
|
32
|
+
*/
|
|
33
|
+
export declare function detectVariantIndex(bambuSettings: JsonRecord): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Which column of Bambu's per-variant filament arrays holds the High Flow
|
|
36
|
+
* value, from the source's own variant names (e.g. "Direct Drive High
|
|
37
|
+
* Flow"). `null` when the source has no named high-flow variant.
|
|
38
|
+
*/
|
|
39
|
+
export declare function detectHighFlowVariantIndex(bambuSettings: JsonRecord): number | null;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Bambu sometimes joins an ordered variant-name list into ONE comma-separated string element instead of separate array elements. */
|
|
2
|
+
function normalizeVariantNames(raw) {
|
|
3
|
+
if (raw.length === 1 && typeof raw[0] === "string" && raw[0].includes(",")) {
|
|
4
|
+
return raw[0].split(",");
|
|
5
|
+
}
|
|
6
|
+
return raw.map((v) => String(v));
|
|
7
|
+
}
|
|
8
|
+
function extractVariantNames(bambuSettings) {
|
|
9
|
+
for (const key of ["filament_extruder_variant", "print_extruder_variant", "printer_extruder_variant", "extruder_variant_list"]) {
|
|
10
|
+
const raw = bambuSettings[key];
|
|
11
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
12
|
+
continue;
|
|
13
|
+
const names = normalizeVariantNames(raw);
|
|
14
|
+
if (names.length >= 2)
|
|
15
|
+
return names;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Determines which column of Bambu's newer per-nozzle-variant paired
|
|
21
|
+
* arrays (e.g. `outer_wall_speed: ["210", "350"]`) reflects the settings
|
|
22
|
+
* Bambu Studio actually sliced with.
|
|
23
|
+
*
|
|
24
|
+
* Bambu Lab's newer hardened-steel nozzles support two flow profiles,
|
|
25
|
+
* "Standard" and "High Flow" -- and several process-level settings then
|
|
26
|
+
* carry one value per variant instead of a single scalar, even on
|
|
27
|
+
* printers with only ONE physical nozzle. The authoritative signal for
|
|
28
|
+
* which one was actually active is `nozzle_volume_type` (or
|
|
29
|
+
* `default_nozzle_volume_type`) -- e.g. `["Standard"]`. Confirmed against
|
|
30
|
+
* a real X1 Carbon export (single nozzle, `single_extruder_multi_material:
|
|
31
|
+
* 1`) that had `nozzle_volume_type: ["Standard"]` while the SELECTED
|
|
32
|
+
* FILAMENT PRESET was still named "... HF" (e.g. "Bambu PETG HF @BBL
|
|
33
|
+
* X1C") -- an initial version of this function used that filament-name
|
|
34
|
+
* "HF" substring as the signal instead, which is wrong: an "HF"-tuned
|
|
35
|
+
* filament preset can still be sliced with the Standard nozzle installed,
|
|
36
|
+
* and Bambu Studio then uses the Standard column regardless of the
|
|
37
|
+
* filament preset's own name.
|
|
38
|
+
*
|
|
39
|
+
* This is unrelated to genuine dual-physical-nozzle printers like the
|
|
40
|
+
* H2D -- deliberately scoped to single-physical-nozzle sources only (see
|
|
41
|
+
* the `nozzle_diameter` length check below), since a real multi-nozzle
|
|
42
|
+
* file might reuse these same field names for a different purpose (which
|
|
43
|
+
* physical nozzle a filament is assigned to), and that hasn't been
|
|
44
|
+
* verified, so this heuristic stays out of its way rather than guess.
|
|
45
|
+
*
|
|
46
|
+
* @returns the column index Bambu Studio actually used, or `null` when no
|
|
47
|
+
* usable signal is present -- callers should fall back to their
|
|
48
|
+
* existing "can't determine, ask for manual review" behavior in that case.
|
|
49
|
+
*/
|
|
50
|
+
export function detectVariantIndex(bambuSettings) {
|
|
51
|
+
const nozzleDiameter = bambuSettings.nozzle_diameter;
|
|
52
|
+
if (!Array.isArray(nozzleDiameter) || nozzleDiameter.length !== 1)
|
|
53
|
+
return null;
|
|
54
|
+
const names = extractVariantNames(bambuSettings);
|
|
55
|
+
if (!names)
|
|
56
|
+
return null;
|
|
57
|
+
const activeVariantRaw = bambuSettings.nozzle_volume_type ?? bambuSettings.default_nozzle_volume_type;
|
|
58
|
+
const activeVariant = Array.isArray(activeVariantRaw) && typeof activeVariantRaw[0] === "string" ? activeVariantRaw[0] : null;
|
|
59
|
+
if (!activeVariant)
|
|
60
|
+
return null;
|
|
61
|
+
// Compare with whitespace stripped -- Bambu spells the same variant
|
|
62
|
+
// "Standard"/"HighFlow" in nozzle_volume_type but "Direct Drive High
|
|
63
|
+
// Flow" (with spaces) in the variant-name lists.
|
|
64
|
+
const normalize = (s) => s.replace(/\s+/g, "").toLowerCase();
|
|
65
|
+
const activeNormalized = normalize(activeVariant);
|
|
66
|
+
const index = names.findIndex((n) => normalize(n).includes(activeNormalized));
|
|
67
|
+
return index >= 0 ? index : 0;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Which column of Bambu's per-variant filament arrays holds the High Flow
|
|
71
|
+
* value, from the source's own variant names (e.g. "Direct Drive High
|
|
72
|
+
* Flow"). `null` when the source has no named high-flow variant.
|
|
73
|
+
*/
|
|
74
|
+
export function detectHighFlowVariantIndex(bambuSettings) {
|
|
75
|
+
const names = extractVariantNames(bambuSettings);
|
|
76
|
+
if (!names)
|
|
77
|
+
return null;
|
|
78
|
+
const index = names.findIndex((n) => n.replace(/\s+/g, "").toLowerCase().includes("highflow"));
|
|
79
|
+
return index >= 0 ? index : null;
|
|
80
|
+
}
|