From 5ec9169bc7929124d8ba0de2a0ff2a8435cd4ae0 Mon Sep 17 00:00:00 2001 From: Harry Loud Date: Thu, 16 Jul 2026 14:44:07 +0100 Subject: [PATCH] Route exclusion travels at planned lift height --- src/libslic3r/GCode.cpp | 17 +++++++++++++---- src/libslic3r/GCodeWriter.cpp | 13 +++++++++++++ src/libslic3r/GCodeWriter.hpp | 3 +++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index b2bdc99192..50a6235f77 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -9044,16 +9044,25 @@ std::string GCode::travel_to(const Point& point, ExtrusionRole role, std::string }; const auto route_around_exclusion_volumes = [&]( Polyline &path, - const std::optional &start_z_override) { + const std::optional &start_z_override, + const bool include_planned_lift = false) { if (m_exclusion_volume_travel_avoidance.empty() || path.size() < 2) return false; const double target_z = z == DBL_MAX ? m_nominal_z : z; + double route_start_z = start_z_override.value_or(nominal_writer_z()); + double route_end_z = target_z; + if (include_planned_lift) { + const Vec2d destination_xy = this->point_to_gcode(path.back()); + std::tie(route_start_z, route_end_z) = m_writer.planned_travel_z( + Vec3d(destination_xy.x(), destination_xy.y(), target_z), + m_need_change_layer_lift_z); + } const ExclusionVolumeTravelAvoidance::Result result = m_exclusion_volume_travel_avoidance.route( to_gcode_polyline(path), - start_z_override.value_or(nominal_writer_z()), - target_z, + route_start_z, + route_end_z, active_extruder_id()); if (!result.rerouted()) return false; @@ -9162,7 +9171,7 @@ std::string GCode::travel_to(const Point& point, ExtrusionRole role, std::string } exclusion_volume_travel_rerouted = - route_around_exclusion_volumes(travel, std::nullopt) || + route_around_exclusion_volumes(travel, std::nullopt, true) || (last_post_before_retract == this->last_pos() && exclusion_volume_travel_rerouted); } else { // Reset the wipe path when traveling, so one would not wipe along an old path. diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 0e80cc1fb7..e60e2fa66b 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -971,6 +971,19 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co return out_string; } +std::pair GCodeWriter::planned_travel_z(const Vec3d &point, const bool force_z) const +{ + double destination_z = point.z(); + if (std::abs(m_to_lift) > EPSILON) { + if ((!this->is_current_position_clear() || m_pos != point) && + m_to_lift + m_pos.z() > point.z()) + destination_z = m_to_lift + m_pos.z(); + } else if (!force_z && !this->will_move_z(point.z())) { + destination_z = m_pos.z(); + } + return { m_pos.z(), destination_z }; +} + std::string GCodeWriter::travel_to_z(double z, const std::string &comment, bool force) { /* If target Z is lower than current Z but higher than nominal Z diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index 8247ab757a..ebefeb0745 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -80,6 +80,9 @@ public: double get_current_speed() const { return m_current_speed;} std::string travel_to_xy(const Vec2d &point, const std::string &comment = std::string()); std::string travel_to_xyz(const Vec3d &point, const std::string &comment = std::string(), bool force_z = false); + // Physical Z range which travel_to_xyz() will emit without mutating writer state. + // This includes an existing lift or a pending lazy lift. + std::pair planned_travel_z(const Vec3d &point, bool force_z = false) const; std::string travel_to_z(double z, const std::string &comment = std::string(), bool force = false); bool will_move_z(double z) const; std::string extrude_to_xy(const Vec2d &point, double dE, const std::string &comment = std::string(), bool force_no_extrusion = false);