# Slicing-pipeline plugins: Python hooks inside `Print::process()` with
an editable geometry API
This branch adds a new **slicing-pipeline** plugin capability on top of
the plugin framework: Python plugins can now run at defined points
inside the slicing pipeline and edit the live slicing data, with changes
cascading into perimeters, infill, and the final G-code.
## The capability
- New plugin type `slicing-pipeline`, selectable per print profile via a
new picker option (`slicing_pipeline_plugin`).
- `Print::process()` fires a hook at 13 pipeline steps (`posSlice`,
`posPerimeters`, … `psSkirtBrim`, `psGCodePostProcess`). Selected
plugins run per step with cancellation honored and failures surfaced as
ordinary slicing errors, never crashes.
- G-code post-processing is folded into this capability as the final
step (`psGCodePostProcess`); the separate "post-processing" plugin type
and its option are removed. Breaking only for the unreleased plugin API
— migrated plugins gain settings and config access in return.
## The Python API (`orca.host`)
- The live print graph is exposed as raw host classes — `Print`,
`PrintObject`, `Layer`, `LayerRegion`, `SurfaceCollection`, `Surface`,
`ExPolygon`, `Polygon`, `Point`, plus `Model`/`TriangleMesh` with
zero-copy numpy views.
- Geometry is genuinely editable through the class API: in-place
transforms, whole-surface replacement, and vertex-level rebuilds, with
`layer.make_slices()` re-deriving the C++ invariants after edits. Write
paths validate input, so malformed data raises in Python instead of
corrupting the slice.
- Bindings are organized under `src/slic3r/plugin/host/` by domain.
## Architecture
- All libslic3r hook seams (capability resolver, pipeline dispatcher)
are installed and uninstalled by one composition root,
`plugin/PluginHooks`, from `PluginManager::initialize()`/`shutdown()`.
GUI_App no longer accumulates per-capability wiring, and hooks detach
before the Python interpreter finalizes.
## Samples (`sandboxes/`) — one per editing idiom
| Sample | Step | Demonstrates |
| --- | --- | --- |
| **Inset Every Slice** | `posSlice` | Shrink every slice via polygon
offset + whole-surface replacement (`slices.set`) |
| **Twistify** | `posSlice` | Twist/taper/wobble via count-preserving
in-place transforms |
| **Fuzzy Slices** | `posSlice` | Fuzzy skin applied to the slice
contours themselves (vertex-level rebuild) — walls, infill, and the
preview all inherit it |
| **G-code Stamp** | `psGCodePostProcess` | Editing the exported G-code
file in place |
# Screenshots/Recordings/Graphs
1. Fuzzy skin example:
Orca's built-in fuzzy skin perturbs the outer-wall EXTRUSION PATHS
during
perimeter generation, so only the printed wall is fuzzy. This sample
instead
perturbs the sliced outline itself at sliced geometry:
<img width="1230" height="902" alt="image"
src="https://github.com/user-attachments/assets/bcf8b0c7-f932-4e6a-985d-7c9cc2f3d7cb"
/>
2. Twistify -- twist/taper/wobble any model at slice time
every layer's sliced surfaces are transformed by a similarity
about the object's bounding-box center as a function of Z
https://github.com/user-attachments/assets/d1309ea8-b01c-4708-adf1-821b3b00a4cc
3. Inset Every Slice -- a small, WORKING SlicingPipeline sample plugin
For every layer/region of the sliced object, this shrinks each
sliced surface by INSET_MM using a real polygon offset
<img width="1225" height="896" alt="image"
src="https://github.com/user-attachments/assets/5f2028a9-ae2a-4aea-8b38-a3d6e24f5cb4"
/>
Experimental fuzzy on geometry
Mirrors libslic3r's fuzzy_polyline on the slice contours at Step.posSlice,
demonstrating the count-changing mutation idiom (rebuild ring via
Polygon.append, write back via ex.contour / ex.set_holes). C++ analogue
test proves area preservation, cascade, and bounded displacement.
GUI_App::on_init_inner() carried the plugin dispatch policy inline (the
capability resolver and the slicing-pipeline dispatcher) and would grow
with every capability that fires from inside libslic3r.
plugin/PluginHooks.{hpp,cpp} now owns one file-local installer per hook,
aggregated by plugin_hooks::install() -- called from
PluginManager::initialize(), reset in shutdown() so no hook can enter
Python after the interpreter finalizes. The wx-side loader subscriptions
move into GUI_App::init_plugin_gui_wiring().
No behavior change; dispatch bodies moved verbatim.
Bind libslic3r's TriangleMesh directly with a shared_ptr holder rather than
wrapping it in a HostTriangleMesh snapshot struct. ModelVolume.mesh() hands
out the volume's own shared_ptr (via const_pointer_cast, which only serves
the holder type), so the Python object pins the snapshot exactly as the
wrapper did, and the zero-copy views now use the Python object as their
array base — deleting the capsule machinery.
The wrapper's type-level constness becomes a documented rule instead:
handed-out meshes are copy-on-write snapshots shared across threads, so the
binding exposes only const methods; a future mutable-mesh API must operate
on plugin-owned copies handed back via ModelVolume::set_mesh.
No Python-visible change (orca.host.TriangleMesh, same methods/docstrings),
and plugins now hold the real class a future set_mesh() will accept.
Verified with slic3rutils and fff_print suites.
PluginHostApi.cpp had grown into one TU holding the module entry point plus
three unrelated domains (presets, model/mesh graph, app access), and
PluginHostSlicing.cpp mixed ownable geometry value types with the
non-owning live print graph. Reorganize the orca.host surface into
plugin/host/ with one registrar per domain:
- PluginHost.hpp/.cpp entry point (replaces PluginHostApi)
- PluginHostBindings.hpp internal per-domain registrar declarations
- PluginHostGeometry.cpp BoundingBox, Point, Polygon, ExPolygon + ndarray parsing
- PluginHostMesh.hpp/.cpp TriangleMesh snapshot (own TU ahead of planned
mesh construct/mutate APIs)
- PluginHostPresets.cpp Preset, PresetCollection, PresetBundle
- PluginHostModel.cpp scene graph: Model, ModelObject, ModelInstance, ModelVolume
- PluginHostApp.cpp Plater + plater()/model()/preset_bundle() accessors
- PluginHostSlicing.cpp live print graph only, now with a single lifetime story
- PluginHostUi.hpp/.cpp moved unchanged
PluginBindingUtils.hpp stays at plugin/ root: it is shared with pluginTypes/
and tests, not host/-specific.
No Python-visible change: same submodules, class names and docstrings.
Verified with slic3rutils and fff_print suites.
Review the slicing-pipeline plugin comments for context a reader of the source
alone cannot follow, and rewrite them to stand on their own:
- drop pointers to uncommitted design/plan material ("§3.6 (Twistify design)",
"the brief's note", "Fix 4(a)/4(b)")
- fix dangling references to code this branch removed: the retired set_slices()
and view mutators, the former G-code post-processing capability/trampoline,
the "Post-processing" capability family, the pre-refactor array helper
- drop "v1"/"in v1" phase labels, keeping the behavior they described
- correct stale cross-references: Twistify.py -> the real sample path;
test_plugin_host_api.cpp:32-40 -> import_orca_module in python_test_support.hpp;
"the binding"/"graphs above" -> the named source
Comment/string-only; no code behavior change.
G-code post-processing is now a step of the slicing-pipeline plugin rather than a
separate capability type. One capability class can transform slices at the geometry
seams AND edit the final G-code, behind a single picker/option.
- Add SlicingPipelineStepPlugin::psGCodePostProcess (bound as
orca.slicing.Step.psGCodePostProcess). Unlike the geometry steps it fires from the
GUI export path in PostProcessor.cpp, not from Print::process(): ctx.print/ctx.object
are None and the plugin edits the file at ctx.gcode_path in place. It may run more
than once per slice (file export and/or upload) and its output is not shown in the
preview.
- Extend SlicingPipelineContext with gcode_path/host/output_name and a C++-only
full_config; config_value() falls back to it when there is no live Print.
- PostProcessor.cpp dispatches SlicingPipelinePluginCapability at psGCodePostProcess,
driven by the existing slicing_pipeline_plugin option.
- The exported G-code lives outside data_dir(), so the plugin audit sandbox would
block the write; the trampoline's audit setup grants ctx.gcode_path's folder as a
scoped allowed root, gated on a non-empty gcode_path so the geometry-step hooks gain
no extra filesystem access.
BREAKING CHANGE: the separate G-code post-processing capability type is removed.
- orca.gcode.GCodePluginCapabilityBase and orca.PluginType.PostProcessing are gone;
post-processing plugins migrate to orca.slicing.SlicingPipelineCapabilityBase +
Step.psGCodePostProcess (and gain ctx.params / ctx.config_value()).
- The post_process_plugin config option is removed; use slicing_pipeline_plugin.
Presets carrying the old key degrade to the standard unknown-key warning.
- Manifest type = "post-processing" now maps to Unknown (advisory only; the loader
dispatches on the C++ get_type()).
Also repairs two latent build breaks the branch carried: stale Step enum value usages
in test_slicing_pipeline_hook.cpp and a reference to the removed
ConfigOptionDef::PluginType::None in Tab::on_value_change (now is_plugin_backed()).
Adds the orca_gcode_stamp sample plugin and a psGCodePostProcess binding test.
Replaces the plugin-only set_slices/set_fill_surfaces/set_lslices mutators with a
faithful, mutable binding of the core geometry types, so a plugin edits the slicing
graph through the same object model the C++ code uses.
- Point, Polygon, ExPolygon, Surface and SurfaceCollection gain constructors,
writable accessors (contour/holes, set/append/clear, filter_by_type), transforms
(rotate/scale/translate), boolean ops and offset. Polygon exposes a zero-copy
writable numpy view via a make_writable_rows helper.
- LayerRegion.slices/fill_surfaces stay read-only refs but are now live,
in-place-editable SurfaceCollections; Layer.make_slices() re-derives the islands
and refreshes lslice bounding boxes.
- Rewrites the Inset and Twistify samples on the new API (in-place ExPolygon
transforms, ExPolygon.offset, SurfaceCollection.set), dropping their numpy
dependency; each touched layer calls make_slices() so downstream steps see the
edited footprint. Adds tests covering in-place edits through a live collection.
BREAKING CHANGE: set_slices/set_fill_surfaces/set_lslices and the internal
parse_expolygon(_list)/surfaces_from_py helpers are removed. Plugins mutate through
the class API (SurfaceCollection.set/append/clear, Polygon.set_points/append,
ExPolygon.set_holes) instead.
Brings in the Plugins dialog as-you-type search with fuzzy match highlighting
and clickable column-header sorting (name, version, source, status) — PRs
#14610 and #14611.
Adds PluginHostSlicing, which registers the print-graph data model (Print,
PrintObject, Layer, LayerRegion, Surface, ExPolygon, extrusions, ...) into the
orca.host submodule in the same raw-class style as PluginHostApi's Model/Preset
graph, with shared helpers in PluginBindingUtils. SlicingPipelinePluginCapability
is trimmed to the capability surface (the standalone SlicingNumpy helper is folded
away). Adds the Twistify example plugin next to Inset and broadens the binding,
hook, and plugin-install tests.
Replace the toolbar sort dropdown with sortable Name/Source/Status column
headers that cycle ascending, descending, then clear. Add a Source column
and a PluginSortKey::None baseline for the cleared state. The whole header
cell is the click target and the sort triangle snaps in without a fade.
Introduces a plugin capability that runs Python at the seams of Print::process(),
letting a plugin read and rewrite slicing state as it is computed.
- New slicing_pipeline_plugin config option; selected plugin refs are serialized
into the print manifest.
- Print gains an injectable hook fired at each pipeline step (posSlice,
posPerimeters, posInfill, ...). It is a no-op when unset, fires only on genuine
(re)computation, and never on the use-cache path.
- orca.slicing submodule: SlicingPipelineCapabilityBase plus a trampoline and a
Step enum. Capabilities read the live graph through zero-copy int64 numpy views
(contour/holes geometry with unscaled coordinates, flattened toolpath data) and
edit it through 2D-geometry mutators with cache-invariant refresh.
- GUI dispatcher runs capabilities during slicing under the GIL, turns plugin
errors into slicing errors, honors cancellation, and adds the plugin picker.
- Ships the InsetEverySlice sample plugin and binding/hook tests.