From d2d97623223fcf4020760f719bf597aa090d6738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Wed, 19 Jun 2024 11:24:29 +0200 Subject: [PATCH] Smooth path for infills --- src/libslic3r/GCode.cpp | 25 ++++++++++++------------- src/libslic3r/GCode.hpp | 2 +- src/libslic3r/GCode/ExtrusionOrder.cpp | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 2d6c40c805..09952921fe 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2332,20 +2332,19 @@ std::vector GCodeGenerator::get_sorte ); } - assert(validate_smooth_path(smooth_path, !enable_loop_clipping)); - + assert(validate_smooth_path(smooth_path, !m_enable_loop_clipping)); result = smooth_path; } else if (auto multipath = dynamic_cast(extrusion_entity)) { - result = smooth_path_caches.layer_local().resolve_or_fit(*multipath, extrusion_reference.flipped(), m_scaled_resolution); + result = smooth_path_caches.layer_local().resolve_or_fit(*multipath, extrusion_reference.flipped(), m_scaled_resolution); } else if (auto path = dynamic_cast(extrusion_entity)) { - result = smooth_path_caches.layer_local().resolve_or_fit(*path, extrusion_reference.flipped(), m_scaled_resolution); + result = GCode::SmoothPath{GCode::SmoothPathElement{path->attributes(), smooth_path_caches.layer_local().resolve_or_fit(*path, extrusion_reference.flipped(), m_scaled_resolution)}}; } using GCode::SmoothPathElement; - for (const SmoothPathElement &element : result) { - if (!element.path.empty()) { - previous_position = element.path.back().point; + for (auto it{result.rbegin()}; it != result.rend(); ++it) { + if (!it->path.empty()) { + previous_position = it->path.back().point; break; } } @@ -3036,22 +3035,22 @@ std::string GCodeGenerator::extrude_skirt( } std::string GCodeGenerator::extrude_infill_range( - const std::vector &sorted_paths, + const std::vector &infill_range, const PrintRegion ®ion, const std::string &extrusion_name, const GCode::SmoothPathCache &smooth_path_cache ) { std::string gcode{}; - if (!sorted_paths.empty()) { + + if (!infill_range.empty()) { this->m_config.apply(region.config()); - for (const GCode::SmoothPath &smooth_path : sorted_paths) { + for (const GCode::SmoothPath &path : infill_range) { // extrude along the path - std::string gcode; - for (const GCode::SmoothPathElement &el : smooth_path) + for (const GCode::SmoothPathElement &el : path) gcode += this->_extrude(el.path_attributes, el.path, extrusion_name); - GCode::SmoothPath reversed_smooth_path{smooth_path}; + GCode::SmoothPath reversed_smooth_path{path}; GCode::reverse(reversed_smooth_path); m_wipe.set_path(std::move(reversed_smooth_path)); diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 2248a6461b..04809992dd 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -308,7 +308,7 @@ private: ); std::string extrude_infill_range( - const std::vector &sorted_paths, + const std::vector &infill_range, const PrintRegion ®ion, const std::string &extrusion_name, const GCode::SmoothPathCache &smooth_path_cache diff --git a/src/libslic3r/GCode/ExtrusionOrder.cpp b/src/libslic3r/GCode/ExtrusionOrder.cpp index d609c71c59..316e7c4bb3 100644 --- a/src/libslic3r/GCode/ExtrusionOrder.cpp +++ b/src/libslic3r/GCode/ExtrusionOrder.cpp @@ -202,7 +202,7 @@ std::vector extract_infill_ranges( for (const ExtrusionEntityReference &extrusion_reference : sorted_extrusions) { std::optional last_position{get_instance_point(previous_position, offset)}; paths.push_back(smooth_path(&layer, extrusion_reference, extruder_id, last_position)); - previous_position = get_gcode_point(previous_position, offset); + previous_position = get_gcode_point(last_position, offset); } result.push_back({std::move(paths), ®ion}); it = it_end;