From f9d55192940c15e0a34aebf08b77ce4a31e582ff Mon Sep 17 00:00:00 2001 From: Kiss Lorand <50251547+kisslorand@users.noreply.github.com> Date: Thu, 18 Dec 2025 14:30:41 +0200 Subject: [PATCH] Scale emulated spiral Z-hop segments based on slicing resolution (#11556) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spiral Z-Hop resolution Use slicing resolution to determine segment count for emulated spiral Z-hop What’s changed The number of linear segments used to approximate a spiral Z-hop is now derived from the PrintConfig resolution value. The segment count is clamped to a safe range (4–24) to avoid excessive G-code generation or MCU queue overflow. Why Previously a fixed 24 segments were always used, regardless of model resolution. For small-radius spiral lifts this was excessive and could overwhelm some printers. Adapting segment count to resolution ensures smooth motion where needed, but lighter G-code where possible. Details m_resolution is now stored via apply_print_config(). _spiral_travel_to_z() uses this value to compute segment count dynamically. Only the linear-segment fallback path is affected; G2/G3 arc-fitting remains unchanged. --- src/libslic3r/GCodeWriter.cpp | 15 +++++++++++++-- src/libslic3r/GCodeWriter.hpp | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 6340a7af5c..f3d218750b 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -42,6 +42,7 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config) }; m_max_jerk_z = print_config.machine_max_jerk_z.values.front(); m_max_jerk_e = print_config.machine_max_jerk_e.values.front(); + m_resolution = print_config.resolution.value; } void GCodeWriter::set_extruders(std::vector extruder_ids) @@ -787,8 +788,18 @@ std::string GCodeWriter::_spiral_travel_to_z(double z, const Vec2d &ij_offset, c if (!this->config.enable_arc_fitting) { // Orca: if arc fitting is disabled, approximate the arc with small linear segments std::ostringstream oss; - const double z_start = m_pos(2); // starting Z height - const int segments = 24; // number of linear segments to use for approximating the arc + const double z_start = m_pos(2); // starting Z height + + // -------------------------------------------------------------------- + // Determine number of segments based on Resolution + // -------------------------------------------------------------------- + const double ref_resolution = 0.01; // reference resolution in mm + const double ref_segments = 16.0; // reference number of segments at reference resolution + + // number of linear segments to use for approximating the arc, clamp between 4 and 24 + const int segments = std::clamp(int(std::round(ref_segments * (ref_resolution / m_resolution))), 4, 24); + // -------------------------------------------------------------------- + const double px = m_pos(0) - m_x_offset; // take plate offset into consideration const double py = m_pos(1) - m_y_offset; // take plate offset into consideration const double cx = px + ij_offset(0); // center x diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index 729c89263e..32e737164d 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -168,6 +168,9 @@ public: //BBS: x, y offset for gcode generated double m_x_offset{ 0 }; double m_y_offset{ 0 }; + + // Orca: slicing resolution in mm + double m_resolution = 0.01; std::string m_gcode_label_objects_start; std::string m_gcode_label_objects_end;