three-slicer-viewer 0.2.5
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/COMPONENTS.md +44 -0
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/THIRD-PARTY-NOTICES.md +19 -0
- package/TOOLPATH_SPEC.md +173 -0
- package/VIEWER.md +423 -0
- package/data/config-schema-lean.json +1 -0
- package/data/preset-keys.json +1 -0
- package/data/ui-tree-keys.json +1 -0
- package/dist/components.js +206 -0
- package/dist/gcode_parse.js +190 -0
- package/dist/index.js +6416 -0
- package/dist/make_worker.js +26 -0
- package/dist/model_loaders.js +183 -0
- package/dist/parse_3mf-CQ5rAX6P.js +299 -0
- package/dist/parse_3mf.worker.js +10 -0
- package/dist/sl1_encode.worker.js +10 -0
- package/dist/sl1_write-CvrNejbW.js +302 -0
- package/dist/sla_reconstruct-CXkYhux2.js +176 -0
- package/dist/sla_reconstruct.worker.js +24 -0
- package/dist/sla_slice.worker.js +73 -0
- package/dist/toolpath.js +408 -0
- package/package.json +83 -0
- package/src/data.js +2 -0
- package/src/settings/data.js +6 -0
- package/src/settings/index.js +2 -0
- package/src/settings/kernel_setting_keys.js +132 -0
- package/src/settings/preset_file.js +99 -0
- package/src/settings/settings_core.js +638 -0
- package/src/settings/toggle_eval.js +90 -0
- package/types/components.d.ts +39 -0
- package/types/data.d.ts +3 -0
- package/types/gcode.d.ts +29 -0
- package/types/index.d.ts +7 -0
- package/types/loaders.d.ts +33 -0
- package/types/settings-keys.d.ts +1855 -0
- package/types/settings.d.ts +173 -0
- package/types/toggle.d.ts +30 -0
- package/types/toolpath.d.ts +138 -0
- package/types/viewer.d.ts +256 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// OrcaSlicer preset files — the `.json` its "Config files (*.json;…)" import accepts, and that its
|
|
2
|
+
// "Export preset" writes. One file holds one preset of one type: machine, process or filament.
|
|
3
|
+
//
|
|
4
|
+
// The value encoding is the same one `project_settings.config` uses, and for the same reason: upstream writes
|
|
5
|
+
// every option through ConfigBase::save_to_json, which serializes each one to a string (a bool is "1"/"0", a point
|
|
6
|
+
// is "XxY", a vector becomes an array of strings). So normalize/serializeProjectSettings are reused verbatim
|
|
7
|
+
// rather than reimplemented — a second copy of that coercion table is exactly how the two would drift.
|
|
8
|
+
//
|
|
9
|
+
// Zero dependencies, so this lives in the engine and works headless. The zip bundle formats (.orca_printer) need
|
|
10
|
+
// a deflate and therefore live in the viewer, which already has one.
|
|
11
|
+
import { leanSchema as schema, presetKeys } from './data.js' // .default is all it reads
|
|
12
|
+
import { normalizeProjectSettings, serializeProjectSettings } from './settings_core.js' // not settings.js: that re-exports this file, and a cycle through it is avoidable
|
|
13
|
+
|
|
14
|
+
/** `machine` for printers, `process` for print settings, `filament` for materials — upstream's own `type` field. */
|
|
15
|
+
const KEY_LIST = { machine: 'printer', process: 'process', filament: 'filament' }
|
|
16
|
+
|
|
17
|
+
// Preset bookkeeping, not settings. Upstream writes six of these; `inherits` is read (it names the parent) and the
|
|
18
|
+
// rest are carried only so a round trip does not lose them.
|
|
19
|
+
const ENVELOPE = new Set(['type', 'name', 'from', 'version', 'setting_id', 'instantiation', 'inherits',
|
|
20
|
+
'filament_id', 'is_custom_defined', 'filament_settings_id', 'print_settings_id', 'printer_settings_id'])
|
|
21
|
+
|
|
22
|
+
/** Every option key that belongs in a preset of this type. */
|
|
23
|
+
export function presetOptionKeys(type) {
|
|
24
|
+
const list = presetKeys[KEY_LIST[type]]
|
|
25
|
+
if (!list) throw new Error(`unknown preset type '${type}' (expected machine, process or filament)`)
|
|
26
|
+
return list
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A settings map -> the object an OrcaSlicer preset `.json` holds.
|
|
31
|
+
*
|
|
32
|
+
* Written **flattened**: no `inherits`, every key present. That is the whole difference between a file another
|
|
33
|
+
* program can read on its own and one that only means something next to the vendor database it was derived from —
|
|
34
|
+
* upstream's own exports are diffs against a parent (`Preset::save`: "only save difference if it has parent"),
|
|
35
|
+
* which is fine for OrcaSlicer reading its own files back and useless for anyone else.
|
|
36
|
+
*
|
|
37
|
+
* `complete: false` writes only the keys the settings map actually holds, for a diff-shaped file.
|
|
38
|
+
*/
|
|
39
|
+
export function writePresetFile(settings, { type = 'machine', name = 'Custom', complete = true, version = '1.0.0.0' } = {}) {
|
|
40
|
+
const keys = presetOptionKeys(type)
|
|
41
|
+
const picked = {}
|
|
42
|
+
for (const key of keys) {
|
|
43
|
+
// `inherits` is in upstream's printer_options list — it is an option to OrcaSlicer's config machinery, but it
|
|
44
|
+
// is bookkeeping here, and writing it would put an empty parent name in a file meant to stand alone. The same
|
|
45
|
+
// ENVELOPE set the reader strips is what the writer refuses to emit, so the two cannot disagree about it.
|
|
46
|
+
if (ENVELOPE.has(key)) continue
|
|
47
|
+
if (settings && key in settings && settings[key] != null) picked[key] = settings[key]
|
|
48
|
+
// A key with no schema default cannot be filled — there is nothing to fill it with. `complete` means "every
|
|
49
|
+
// option that HAS a value", not "every option name", and inventing one would be worse than leaving it out.
|
|
50
|
+
else if (complete && schema[key]?.default !== undefined) picked[key] = schema[key].default
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
type, name, from: 'User', version, instantiation: 'true',
|
|
54
|
+
...serializeProjectSettings(picked),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The inverse: a parsed preset `.json` -> a settings map this package accepts.
|
|
60
|
+
*
|
|
61
|
+
* `inherits` is the trap. Upstream stores a derived preset as the DIFF against its parent, so a vendor file on its
|
|
62
|
+
* own carries a fraction of the preset — the Bambu X1C machine json inherits `fdm_bbl_3dp_001_common` and lists
|
|
63
|
+
* about twenty keys. Resolution therefore needs a parent lookup, and this package has no full preset database:
|
|
64
|
+
* `resolveParent(name)` is the hook, and `printerSettings` covers the machine case for the keys the kernel reads.
|
|
65
|
+
*
|
|
66
|
+
* When the parent cannot be resolved the file's own values are still applied and `missingParent` names it —
|
|
67
|
+
* dropping a whole file because one name is unknown loses more than it protects, and the caller can decide.
|
|
68
|
+
*/
|
|
69
|
+
export function readPresetFile(raw, { resolveParent } = {}) {
|
|
70
|
+
if (!raw || typeof raw !== 'object') throw new Error('not a preset object')
|
|
71
|
+
const type = raw.type
|
|
72
|
+
if (!KEY_LIST[type]) throw new Error(`not an OrcaSlicer preset: type is ${JSON.stringify(type)}`)
|
|
73
|
+
|
|
74
|
+
const own = {}
|
|
75
|
+
for (const [key, value] of Object.entries(raw)) if (!ENVELOPE.has(key)) own[key] = value
|
|
76
|
+
const { settings, applied, skipped } = normalizeProjectSettings(own)
|
|
77
|
+
|
|
78
|
+
// The parent goes UNDER the file's own values — the file is the diff, so it wins.
|
|
79
|
+
let missingParent = null
|
|
80
|
+
let merged = settings
|
|
81
|
+
if (raw.inherits) {
|
|
82
|
+
const parent = resolveParent?.(raw.inherits, type) ?? null
|
|
83
|
+
if (parent) merged = { ...parent, ...settings }
|
|
84
|
+
else missingParent = raw.inherits
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
settings: merged,
|
|
89
|
+
type,
|
|
90
|
+
name: typeof raw.name === 'string' ? raw.name : '',
|
|
91
|
+
inherits: raw.inherits ?? null,
|
|
92
|
+
missingParent,
|
|
93
|
+
applied,
|
|
94
|
+
skipped,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Convenience: the JSON text an export writes. */
|
|
99
|
+
export const presetFileText = (settings, options) => JSON.stringify(writePresetFile(settings, options), null, 1)
|