From 2dc49002921aa2db525831a8f2325f69f705e4f9 Mon Sep 17 00:00:00 2001 From: Joseph Robertson <32232925+HarrierPigeon@users.noreply.github.com> Date: Wed, 27 May 2026 21:53:04 -0500 Subject: [PATCH] Copilot review fixes & upstream code interaction fix (#34) * first pass at review issue 8 * delete detritus * fix build compile error due to upstream changes --- result.json | 7 ------- src/libslic3r/Print.hpp | 8 ++++++++ src/libslic3r/PrintObject.cpp | 19 +++++++++++++------ src/libslic3r/PrintObjectSlice.cpp | 7 +++++++ src/slic3r/GUI/3DScene.cpp | 5 +---- 5 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 result.json diff --git a/result.json b/result.json deleted file mode 100644 index e309ad45a1..0000000000 --- a/result.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "error_string": "Success.", - "export_time": 0, - "plate_index": 0, - "prepare_time": 0, - "return_code": 0 -} diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 98d1e6fa5c..269c407762 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -589,6 +589,14 @@ private: double m_belt_min_z { 0.0 }; // Belt printer: XY correction from global pre-slice mode, applied to G-code origin. Vec2d m_belt_global_xy_correction { Vec2d::Zero() }; + // Belt printer: exact belt_floor_z_shift computed during posSlice from a + // vertex-level scan of the post-transform mesh. Cached separately from + // m_slicing_params so that rebuilding m_slicing_params on a non-belt-affecting + // invalidation (e.g. support config change) doesn't replace the exact value + // with the bbox approximation seeded by create_from_config(). Cleared when + // posSlice is invalidated. + double m_belt_floor_z_shift_cached { 0.0 }; + bool m_belt_floor_z_shift_cache_valid { false }; public: double belt_global_z_offset() const { return m_belt_global_z_offset; } double belt_min_z() const { return m_belt_min_z; } diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 309f497412..c1d01c6c68 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1461,15 +1461,16 @@ bool PrintObject::invalidate_step(PrintObjectStep step) invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posContouring, posSupportMaterial, posSimplifyPath, posSimplifyInfill }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); m_slicing_params.valid = false; + // The exact belt_floor_z_shift is recomputed when slice() runs again. + m_belt_floor_z_shift_cache_valid = false; } else if (step == posSupportMaterial) { invalidated |= this->invalidate_steps({ posSimplifySupportPath }); invalidated |= m_print->invalidate_steps({ psSkirtBrim }); - // NOTE: do NOT set m_slicing_params.valid = false here. - // belt_floor_z_shift is patched to an exact value during posSlice - // (PrintObjectSlice.cpp, after slice_volumes). Invalidating slicing - // params here causes update_slicing_parameters() to overwrite that - // exact value with a bounding-box approximation, while posSlice does - // not re-run to correct it — breaking belt support clipping. + // SlicingParameters depend on support config (enable_support / + // raft_layers / enforce_support_layers feed min/max layer height in + // Slicing.cpp), so invalidate them here. The vertex-scan + // belt_floor_z_shift is preserved via m_belt_floor_z_shift_cached. + m_slicing_params.valid = false; } // Wipe tower depends on the ordering of extruders, which in turn depends on everything. @@ -1487,6 +1488,7 @@ bool PrintObject::invalidate_all_steps() bool result = Inherited::invalidate_all_steps() | m_print->invalidate_all_steps(); // Then reset some of the depending values. m_slicing_params.valid = false; + m_belt_floor_z_shift_cache_valid = false; return result; } @@ -3654,6 +3656,11 @@ void PrintObject::update_slicing_parameters() m_slicing_params.belt_floor_shear_factor = belt_floor.shear_factor; m_slicing_params.belt_floor_from_axis = belt_floor.from_axis; m_slicing_params.belt_floor_z_shift = belt_floor.z_shift; + // Prefer the vertex-scan z_shift over the bbox approximation when + // slice() has already produced one (e.g. this rebuild was triggered + // by a support-config change, which doesn't move the belt floor). + if (m_belt_floor_z_shift_cache_valid) + m_slicing_params.belt_floor_z_shift = m_belt_floor_z_shift_cached; } } diff --git a/src/libslic3r/PrintObjectSlice.cpp b/src/libslic3r/PrintObjectSlice.cpp index bb5af8c342..deaf6fdfce 100644 --- a/src/libslic3r/PrintObjectSlice.cpp +++ b/src/libslic3r/PrintObjectSlice.cpp @@ -1164,6 +1164,13 @@ void PrintObject::slice() << " center_offset=(" << unscale(m_center_offset.x()) << ", " << unscale(m_center_offset.y()) << ")"; } + + // Cache the final patched belt_floor_z_shift so a later support-only + // invalidation can rebuild m_slicing_params without losing this exact + // (vertex-scan-derived) value. update_slicing_parameters() will + // restore it after create_from_config() seeds the bbox approximation. + m_belt_floor_z_shift_cached = m_slicing_params.belt_floor_z_shift; + m_belt_floor_z_shift_cache_valid = true; } } diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index bfa2b933a2..e9910a2eed 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1117,10 +1117,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, shader->set_uniform("print_volume.type", -1); } - bool enable_support; - int support_threshold_angle = get_selection_support_threshold_angle(enable_support); - - float normal_z = -::cos(Geometry::deg2rad((float) support_threshold_angle)); + const float normal_z = get_selection_support_normal_z(); // Compute up direction accounting for build plate tilt Vec3f up_direction = Vec3f::UnitZ();