diff --git a/src/libslic3r/GCode/SpiralVase.cpp b/src/libslic3r/GCode/SpiralVase.cpp index 85af021ea1f..eae77292bdd 100644 --- a/src/libslic3r/GCode/SpiralVase.cpp +++ b/src/libslic3r/GCode/SpiralVase.cpp @@ -136,59 +136,56 @@ std::string SpiralVase::process_layer(const std::string &gcode, bool last_layer) return; } else { float dist_XY = line.dist_XY(reader); - if (dist_XY > 0) { - // horizontal move - if (line.extruding(reader)) { // We need this to exclude retract and wipe moves! - len += dist_XY; - float factor = len / total_layer_length; - if (transition_in) - // Transition layer, interpolate the amount of extrusion from zero to the final value. - line.set(reader, E, line.e() * factor); - else if (transition_out) { - // We want the last layer to ramp down extrusion, but without changing z height! - // So clone the line before we mess with its Z and duplicate it into a new layer that ramps down E - // We add this new layer at the very end - GCodeReader::GCodeLine transitionLine(line); - transitionLine.set(reader, E, line.e() * (1 - factor)); - transition_gcode += transitionLine.raw() + '\n'; - } - // This line is the core of Spiral Vase mode, ramp up the Z smoothly - line.set(reader, Z, z + factor * layer_height); - if (smooth_spiral) { - // Now we also need to try to interpolate X and Y - SpiralPoint p(line.x(), line.y()); // Get current x/y coordinates - current_layer->push_back(p); // Store that point for later use on the next layer - - if (previous_layer != NULL) { - bool found = false; - float dist = 0; - SpiralPoint nearestp = nearest_point_on_polygon(p, previous_layer, found, dist); - if (found && dist < max_xy_dist_for_smoothing) { - // Interpolate between the point on this layer and the point on the previous layer - SpiralPoint target = add(scale(nearestp, 1 - factor), scale(p, factor)); - line.set(reader, X, target.x); - line.set(reader, Y, target.y); - // We need to figure out the distance of this new line! - float modified_dist_XY = distance(last_point, target); - line.set(reader, E, - line.e() * modified_dist_XY / dist_XY); // Scale the extrusion amount according to change in length - last_point = target; - } else { - last_point = p; - } + // horizontal move that is not retract or wipe + if (dist_XY > 0 && line.extruding(reader)) { + len += dist_XY; + float factor = len / total_layer_length; + if (transition_in) + // Transition layer, interpolate the amount of extrusion from zero to the final value. + line.set(reader, E, line.e() * factor, 5 /*decimal_digits*/); + else if (transition_out) { + // We want the last layer to ramp down extrusion, but without changing z height! + // So clone the line before we mess with its Z and duplicate it into a new layer that ramps down E + // We add this new layer at the very end + GCodeReader::GCodeLine transitionLine(line); + transitionLine.set(reader, E, line.e() * (1 - factor), 5 /*decimal_digits*/); + transition_gcode += transitionLine.raw() + '\n'; + } + // This line is the core of Spiral Vase mode, ramp up the Z smoothly + line.set(reader, Z, z + factor * layer_height); + if (smooth_spiral) { + // Now we also need to try to interpolate X and Y + SpiralPoint p(line.x(), line.y()); // Get current x/y coordinates + current_layer->push_back(p); // Store that point for later use on the next layer + if (previous_layer != NULL) { + bool found = false; + float dist = 0; + SpiralPoint nearestp = nearest_point_on_polygon(p, previous_layer, found, dist); + if (found && dist < max_xy_dist_for_smoothing) { + // Interpolate between the point on this layer and the point on the previous layer + SpiralPoint target = add(scale(nearestp, 1 - factor), scale(p, factor)); + line.set(reader, X, target.x); + line.set(reader, Y, target.y); + // We need to figure out the distance of this new line! + float modified_dist_XY = distance(last_point, target); + // Scale the extrusion amount according to change in length + line.set(reader, E, line.e() * modified_dist_XY / dist_XY, 5 /*decimal_digits*/); + last_point = target; + } else { + last_point = p; } } - new_gcode += line.raw() + '\n'; } - return; - /* Skip travel moves: the move to first perimeter point will - cause a visible seam when loops are not aligned in XY; by skipping - it we blend the first loop move in the XY plane (although the smoothness - of such blend depend on how long the first segment is; maybe we should - enforce some minimum length?). - When smooth_spiral is enabled, we're gonna end up exactly where the next layer should - start anyway, so we don't need the travel move */ + new_gcode += line.raw() + '\n'; } + return; + /* Skip travel moves: the move to first perimeter point will + cause a visible seam when loops are not aligned in XY; by skipping + it we blend the first loop move in the XY plane (although the smoothness + of such blend depend on how long the first segment is; maybe we should + enforce some minimum length?). + When smooth_spiral is enabled, we're gonna end up exactly where the next layer should + start anyway, so we don't need the travel move */ } } new_gcode += line.raw() + '\n';