From 7c6ecf8a06302c4896fa1477a3f9e98b5c91587f Mon Sep 17 00:00:00 2001 From: EiNSTeiN- Date: Sun, 2 Jul 2023 14:21:33 -0400 Subject: [PATCH] Fix artifacts created when manipulating extrusion loops and other gcode generation issues --- src/libslic3r/GCode.cpp | 8 ++++++-- src/libslic3r/Polyline.cpp | 14 +++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index d5919f552..5b4b0a651 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2787,10 +2787,11 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, const std::string_view descr // Shift by no more than a nozzle diameter. //FIXME Hiding the seams will not work nicely for very densely discretized contours! Point pt = ((nd * nd >= l2) ? p2 : (p1 + v * (nd / sqrt(l2)))).cast(); + pt.nonplanar_z = paths.front().polyline.points.front().nonplanar_z; // Rotate pt inside around the seam point. pt.rotate(angle_inside / 3., paths.front().polyline.points.front()); // generate the travel move - gcode += m_writer.travel_to_xy(this->point_to_gcode(pt), "move inwards before travel"); + gcode += m_writer.travel_to_xyz(this->point3_to_gcode(pt), "move inwards before travel"); } return gcode; @@ -3279,7 +3280,10 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string // Move Z up if necessary if (needs_zmove) { - gcode += m_writer.travel_to_z(this->layer()->print_z, "Move up for non planar extrusion"); + float move_z = unscale(travel.points[0].nonplanar_z); + if(travel.points[0].nonplanar_z == -1) + move_z = this->layer()->print_z; + gcode += m_writer.travel_to_z(move_z, "Move up for non planar extrusion"); } gcode += m_writer.set_travel_acceleration((unsigned int)(m_config.travel_acceleration.value + 0.5)); diff --git a/src/libslic3r/Polyline.cpp b/src/libslic3r/Polyline.cpp index ec7732ccf..05ecc444a 100644 --- a/src/libslic3r/Polyline.cpp +++ b/src/libslic3r/Polyline.cpp @@ -51,7 +51,9 @@ void Polyline::clip_end(double distance) Vec2d v = this->last_point().cast() - last_point; double lsqr = v.squaredNorm(); if (lsqr > distance * distance) { - this->points.emplace_back((last_point + v * (distance / sqrt(lsqr))).cast()); + Point p((last_point + v * (distance / sqrt(lsqr))).cast()); + p.nonplanar_z = this->last_point().nonplanar_z; + this->points.emplace_back(p); return; } distance -= sqrt(lsqr); @@ -102,7 +104,9 @@ Points Polyline::equally_spaced_points(double distance) const continue; } double take = segment_length - (len - distance); // how much we take of this segment - points.emplace_back((p1 + v * (take / v.norm())).cast()); + Point p((p1 + v * (take / v.norm())).cast()); + p.nonplanar_z = (*it).nonplanar_z; + points.emplace_back(p); -- it; len = - take; } @@ -247,6 +251,7 @@ std::pair foot_pt(const Points &polyline, const Point &pt) if (double d2 = line_alg::distance_to_squared(Line(prev, *it), pt, &foot_pt); d2 < d2_min) { d2_min = d2; foot_pt_min = foot_pt; + foot_pt_min.nonplanar_z = (*it).nonplanar_z; it_proj = it; } prev = *it; @@ -272,6 +277,7 @@ void ThickPolyline::clip_end(double distance) assert(this->width.size() == (this->points.size() - 1) * 2); while (distance > 0) { Vec2d last_point = this->last_point().cast(); + coord_t last_z = this->last_point().nonplanar_z; this->points.pop_back(); if (this->points.empty()) { assert(this->width.empty()); @@ -285,7 +291,9 @@ void ThickPolyline::clip_end(double distance) double vec_length_sqr = vec.squaredNorm(); if (vec_length_sqr > distance * distance) { double t = (distance / std::sqrt(vec_length_sqr)); - this->points.emplace_back((last_point + vec * t).cast()); + Point p((last_point + vec * t).cast()); + p.nonplanar_z = last_z; + this->points.emplace_back(p); this->width.emplace_back(last_width + width_diff * t); assert(this->width.size() == (this->points.size() - 1) * 2); return;