diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 86a89fd6f2..ba391ab63f 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2343,7 +2343,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou const EdgeGrid::Grid* edge_grid_ptr = (lower_layer_edge_grid && *lower_layer_edge_grid) ? lower_layer_edge_grid->get() : nullptr; - Point seam = m_seam_placer.get_seam(m_layer->id(), seam_position, loop, + Point seam = m_seam_placer.get_seam(*m_layer, seam_position, loop, last_pos, EXTRUDER_CONFIG(nozzle_diameter), (m_layer == NULL ? nullptr : m_layer->object()), was_clockwise, edge_grid_ptr); diff --git a/src/libslic3r/GCode/SeamPlacer.cpp b/src/libslic3r/GCode/SeamPlacer.cpp index ff01621b8a..243b633fce 100644 --- a/src/libslic3r/GCode/SeamPlacer.cpp +++ b/src/libslic3r/GCode/SeamPlacer.cpp @@ -6,6 +6,7 @@ #include "libslic3r/EdgeGrid.hpp" #include "libslic3r/ClipperUtils.hpp" #include "libslic3r/SVG.hpp" +#include "libslic3r/Layer.hpp" namespace Slic3r { @@ -282,7 +283,7 @@ void SeamPlacer::init(const Print& print) -Point SeamPlacer::get_seam(const size_t layer_idx, const SeamPosition seam_position, +Point SeamPlacer::get_seam(const Layer& layer, const SeamPosition seam_position, const ExtrusionLoop& loop, Point last_pos, coordf_t nozzle_dmr, const PrintObject* po, bool was_clockwise, const EdgeGrid::Grid* lower_layer_edge_grid) { @@ -292,6 +293,25 @@ Point SeamPlacer::get_seam(const size_t layer_idx, const SeamPosition seam_posit size_t po_idx = std::find(m_po_list.begin(), m_po_list.end(), po) - m_po_list.begin(); + // Find current layer in respective PrintObject. Cache the result so the + // lookup is only done once per layer, not for each loop. + const Layer* layer_po = nullptr; + if (po == m_last_po && layer.print_z == m_last_print_z) + layer_po = m_last_layer_po; + else { + layer_po = po->get_layer_at_printz(layer.print_z); + m_last_po = po; + m_last_print_z = layer.print_z; + m_last_layer_po = layer_po; + } + if (! layer_po) + return last_pos; + + // Index of this layer in the respective PrintObject. + size_t layer_idx = layer_po->id() - po->layers().front()->id(); // raft layers + + assert(layer_idx < po->layer_count()); + if (this->is_custom_seam_on_layer(layer_idx, po_idx)) { // Seam enf/blockers can begin and end in between the original vertices. // Let add extra points in between and update the leghths. diff --git a/src/libslic3r/GCode/SeamPlacer.hpp b/src/libslic3r/GCode/SeamPlacer.hpp index 28ab913134..759e1592eb 100644 --- a/src/libslic3r/GCode/SeamPlacer.hpp +++ b/src/libslic3r/GCode/SeamPlacer.hpp @@ -13,6 +13,7 @@ namespace Slic3r { class PrintObject; class ExtrusionLoop; class Print; +class Layer; namespace EdgeGrid { class Grid; } @@ -40,7 +41,7 @@ class SeamPlacer { public: void init(const Print& print); - Point get_seam(const size_t layer_idx, const SeamPosition seam_position, + Point get_seam(const Layer& layer, const SeamPosition seam_position, const ExtrusionLoop& loop, Point last_pos, coordf_t nozzle_diameter, const PrintObject* po, bool was_clockwise, const EdgeGrid::Grid* lower_layer_edge_grid); @@ -55,6 +56,11 @@ private: TreeType tree; }; + // Just a cache to save some lookups. + const Layer* m_last_layer_po = nullptr; + coordf_t m_last_print_z = -1.; + const PrintObject* m_last_po = nullptr; + std::vector> m_enforcers; std::vector> m_blockers;