diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index edb3f6b8b..35b2e7f03 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -835,7 +835,13 @@ void PerimeterGenerator::process_classic() // BBS: don't simplify too much which influence arc fitting when export gcode if arc_fitting is enabled double surface_simplify_resolution = (print_config->enable_arc_fitting && this->config->fuzzy_skin == FuzzySkinType::None) ? 0.2 * m_scaled_resolution : m_scaled_resolution; - for (const Surface &surface : this->slices->surfaces) { + //BBS: reorder the surface to reduce the travel time + ExPolygons surface_exp; + for (const Surface &surface : this->slices->surfaces) + surface_exp.push_back(surface.expolygon); + std::vector surface_order = chain_expolygons(surface_exp); + for (size_t order_idx = 0; order_idx < surface_order.size(); order_idx++) { + const Surface &surface = this->slices->surfaces[surface_order[order_idx]]; // detect how many perimeters must be generated for this island int loop_number = this->config->wall_loops + surface.extra_perimeters - 1; // 0-indexed loops //BBS: set the topmost and bottom most layer to be one wall diff --git a/src/libslic3r/ShortestPath.cpp b/src/libslic3r/ShortestPath.cpp index 9d1483960..56b1234c1 100644 --- a/src/libslic3r/ShortestPath.cpp +++ b/src/libslic3r/ShortestPath.cpp @@ -1057,6 +1057,16 @@ void chain_and_reorder_extrusion_paths(std::vector &extrusion_pat reorder_extrusion_paths(extrusion_paths, chain_extrusion_paths(extrusion_paths, start_near)); } +std::vector chain_expolygons(const ExPolygons &input_exploy) { + Points points; + for (const ExPolygon &exploy : input_exploy) { + BoundingBox bbox; + bbox = get_extents(exploy); + points.push_back(bbox.center()); + } + return chain_points(points); +} + std::vector chain_points(const Points &points, Point *start_near) { auto segment_end_point = [&points](size_t idx, bool /* first_point */) -> const Point& { return points[idx]; }; diff --git a/src/libslic3r/ShortestPath.hpp b/src/libslic3r/ShortestPath.hpp index e68e1c49d..5a34ef23c 100644 --- a/src/libslic3r/ShortestPath.hpp +++ b/src/libslic3r/ShortestPath.hpp @@ -13,6 +13,7 @@ namespace ClipperLib { class PolyNode; } namespace Slic3r { std::vector chain_points(const Points &points, Point *start_near = nullptr); +std::vector chain_expolygons(const ExPolygons &input_exploy); std::vector> chain_extrusion_entities(std::vector &entities, const Point *start_near = nullptr); void reorder_extrusion_entities(std::vector &entities, const std::vector> &chain);