Fix artifacts created when manipulating extrusion loops and other gcode generation issues

This commit is contained in:
EiNSTeiN- 2023-07-02 14:21:33 -04:00
parent 22c42b9844
commit 7c6ecf8a06
2 changed files with 17 additions and 5 deletions

View File

@ -2787,10 +2787,11 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, const std::string_view descr
// Shift by no more than a nozzle diameter. // Shift by no more than a nozzle diameter.
//FIXME Hiding the seams will not work nicely for very densely discretized contours! //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<coord_t>(); Point pt = ((nd * nd >= l2) ? p2 : (p1 + v * (nd / sqrt(l2)))).cast<coord_t>();
pt.nonplanar_z = paths.front().polyline.points.front().nonplanar_z;
// Rotate pt inside around the seam point. // Rotate pt inside around the seam point.
pt.rotate(angle_inside / 3., paths.front().polyline.points.front()); pt.rotate(angle_inside / 3., paths.front().polyline.points.front());
// generate the travel move // 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; return gcode;
@ -3279,7 +3280,10 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string
// Move Z up if necessary // Move Z up if necessary
if (needs_zmove) { if (needs_zmove) {
gcode += m_writer.travel_to_z(this->layer()->print_z, "Move up for non planar extrusion"); float move_z = unscale<double>(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)); gcode += m_writer.set_travel_acceleration((unsigned int)(m_config.travel_acceleration.value + 0.5));

View File

@ -51,7 +51,9 @@ void Polyline::clip_end(double distance)
Vec2d v = this->last_point().cast<double>() - last_point; Vec2d v = this->last_point().cast<double>() - last_point;
double lsqr = v.squaredNorm(); double lsqr = v.squaredNorm();
if (lsqr > distance * distance) { if (lsqr > distance * distance) {
this->points.emplace_back((last_point + v * (distance / sqrt(lsqr))).cast<coord_t>()); Point p((last_point + v * (distance / sqrt(lsqr))).cast<coord_t>());
p.nonplanar_z = this->last_point().nonplanar_z;
this->points.emplace_back(p);
return; return;
} }
distance -= sqrt(lsqr); distance -= sqrt(lsqr);
@ -102,7 +104,9 @@ Points Polyline::equally_spaced_points(double distance) const
continue; continue;
} }
double take = segment_length - (len - distance); // how much we take of this segment double take = segment_length - (len - distance); // how much we take of this segment
points.emplace_back((p1 + v * (take / v.norm())).cast<coord_t>()); Point p((p1 + v * (take / v.norm())).cast<coord_t>());
p.nonplanar_z = (*it).nonplanar_z;
points.emplace_back(p);
-- it; -- it;
len = - take; len = - take;
} }
@ -247,6 +251,7 @@ std::pair<int, Point> 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) { if (double d2 = line_alg::distance_to_squared(Line(prev, *it), pt, &foot_pt); d2 < d2_min) {
d2_min = d2; d2_min = d2;
foot_pt_min = foot_pt; foot_pt_min = foot_pt;
foot_pt_min.nonplanar_z = (*it).nonplanar_z;
it_proj = it; it_proj = it;
} }
prev = *it; prev = *it;
@ -272,6 +277,7 @@ void ThickPolyline::clip_end(double distance)
assert(this->width.size() == (this->points.size() - 1) * 2); assert(this->width.size() == (this->points.size() - 1) * 2);
while (distance > 0) { while (distance > 0) {
Vec2d last_point = this->last_point().cast<double>(); Vec2d last_point = this->last_point().cast<double>();
coord_t last_z = this->last_point().nonplanar_z;
this->points.pop_back(); this->points.pop_back();
if (this->points.empty()) { if (this->points.empty()) {
assert(this->width.empty()); assert(this->width.empty());
@ -285,7 +291,9 @@ void ThickPolyline::clip_end(double distance)
double vec_length_sqr = vec.squaredNorm(); double vec_length_sqr = vec.squaredNorm();
if (vec_length_sqr > distance * distance) { if (vec_length_sqr > distance * distance) {
double t = (distance / std::sqrt(vec_length_sqr)); double t = (distance / std::sqrt(vec_length_sqr));
this->points.emplace_back((last_point + vec * t).cast<coord_t>()); Point p((last_point + vec * t).cast<coord_t>());
p.nonplanar_z = last_z;
this->points.emplace_back(p);
this->width.emplace_back(last_width + width_diff * t); this->width.emplace_back(last_width + width_diff * t);
assert(this->width.size() == (this->points.size() - 1) * 2); assert(this->width.size() == (this->points.size() - 1) * 2);
return; return;