feat: G2/G3 Arc Support + Bambu Studio Wipe Fix#51
Closed
adele-with-a-b wants to merge 2 commits intoGeekDetour:mainfrom
Closed
feat: G2/G3 Arc Support + Bambu Studio Wipe Fix#51adele-with-a-b wants to merge 2 commits intoGeekDetour:mainfrom
adele-with-a-b wants to merge 2 commits intoGeekDetour:mainfrom
Conversation
…sion fix Arc bounding box: - compute_arc() on GCodeStateBBox computes true arc bbox via cardinal angle crossing detection for G2/G3 moves in loop depth calculation Arc-aware wipe: - wipe() and wipe_movement() use true arc path length and arc interpolation instead of chord distance for G2/G3 segments - New helpers: Point.arc_length(), Point.point_along_arc(), Point.parse_arc_ij(), _wipe_segment_info(), _wipe_interpolate() Absolute extrusion fix (issue GeekDetour#17): - G92 E reset after deferred perimeters uses pre-deferred E value (last_noninternalperimeter_state.e) instead of myline.previous.e - Fixes blob at outer wall start in PrusaSlicer absolute extrusion mode - No-op for Bambu Studio/OrcaSlicer (relative extrusion)
BrickLayers was storing travel line references during wipe blocks, then replacing them with Travel Fix Up moves that broke the wipe sequence. This caused: 1. Missing chunks in Bambu Studio's G-code preview 2. Incomplete nozzle wipe at brick layer transitions (print quality) One-line fix: added 'and not feature.wiping' check when storing last_noninternalperimeter_xy_line reference. Affects Bambu Studio format only — OrcaSlicer format was unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: G2/G3 Arc Support — Bounding Box, Wipe Path, and Absolute Extrusion Fix
This PR adds proper G2/G3 arc support to BrickLayers across three areas, enabling users to safely use Arc Fitting in their slicer without needing to disable it.
Summary of Changes
GCodeStateBBoxonly used arc endpoints, ignoring the arc bulgecompute_arc()method computes true arc bounding box via cardinal angle crossing detectionwipe()andwipe_movement()used chord distance for G2/G3 segmentsG92 Ereset used wrong E value after deferred perimeters1. Arc Bounding Box (
compute_arc)The existing
GCodeStateBBox.compute()only feeds the arc endpoint into the bounding box. For arcs that bulge beyond their endpoints (any arc crossing a cardinal angle — 0°, 90°, 180°, 270°), this underestimates the bounding box.compute_arc()computes the true bounding box by:Unit tests: 10/10 passing across quarter circles, semicircles, full circles, 270° arcs, small arcs, cardinal crossings, tiny radius fallback, and offset centers.
Visual proof (blue dashed = correct arc bbox, red dotted = endpoint-only bbox):
Real-world impact: Tested with a petal vase model (78K+ arc commands). The patch corrected 1 loop placement (48 G-code lines changed). Current slicers produce short arcs (median 6.3° sweep) so the impact is small but prevents edge cases. With arc fitting OFF, output is identical (zero regression).
2. Arc-Aware Wipe Path
The
wipe()andwipe_movement()functions retrace part of the printed loop while retracting. They calculate segment distance usingPoint.distance_between_points()— the chord length. For G2/G3 arcs, the actual path length is longer than the chord.Problems this caused:
Fix: New helper methods detect G2/G3 segments and use true arc length and arc interpolation:
Point.arc_length()— computesr × sweep_anglePoint.point_along_arc()— interpolates a point at a given distance along the arcPoint.parse_arc_ij()— extracts I/J offsets from G-code string_wipe_segment_info()/_wipe_interpolate()— shared helpers used by both wipe functionsTest results (star vase, 49K arc commands, arc fitting ON):
E-0.00054artifacts gone)Sample diff:
3. Absolute Extrusion E Reset (Issue #17)
When BrickLayers defers inner wall perimeters and replays them with relative extrusion (M83), the
G92 Ereset at the end usedmyline.previous.e— the E value that includes the deferred perimeters' extrusion. But since those perimeters were replayed with relative extrusion, the firmware's E register never advanced by that amount.This caused a massive blob at the start of the next feature (outer wall) in PrusaSlicer with absolute extrusion mode, as reported in #17.
Fix:
G92 Enow usesself.last_noninternalperimeter_state.e— the E value from before the deferred perimeters. Applied to bothgenerate_deffered_perimeters()and the kept perimeters path.Note: This is a no-op for Bambu Studio and OrcaSlicer which use relative extrusion (M83) by default.
Testing
tests/test_compute_arc.py— 10/10 geometric correctness teststests/visualize_arc_bbox.pygenerates bbox comparison diagrampr-validation/compare_before_after.py (local)runs unpatched vs patched on any G-code fileFiles Changed
bricklayers.py— 199 insertions, 29 deletionsREADME Update
With these changes, the "Disable Arc fitting (for now)" warning in the README can be removed or updated to indicate arc fitting is now supported.
Related
4. Wipe Block Travel Fix (Bambu Studio Preview)
BrickLayers was storing travel line references during wipe blocks (
; WIPE_START/; WIPE_END), then replacing them withBRICK: Travel Fix Upmoves that included Z changes. This broke the wipe sequence in two ways:Fix: One-line change — added
and not feature.wipingcheck when storing thelast_noninternalperimeter_xy_linereference (line 2188). This prevents BrickLayers from modifying travel moves that are part of a wipe sequence.Impact: Affects Bambu Studio format G-code only. OrcaSlicer format was unaffected because its wipe handling doesn't produce the same travel pattern inside wipe blocks.
Verification: Sliced
BrickLayersChallengeSimple.stlin Bambu Studio with BrickLayers enabled — missing chunks in preview are gone. Dragging the exported G-code into unmodified Bambu Studio also renders correctly.Slicer Preview
BambuStudio and OrcaSlicer do not automatically show post-processing script changes in the preview — you normally have to export the G-code and drag it back in.
A patched BambuStudio fork is available that re-parses G-code after post-processing scripts run, showing the BrickLayers toolpath directly in the preview without manual re-import. The wipe fix in this PR is required for the preview to render correctly without missing chunks.