diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5678ce6f78..032f04dfef 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2422,10 +2422,10 @@ void GCodeGenerator::process_layer_single_object( m_avoid_crossing_perimeters.init_layer(*m_layer); // When starting a new object, use the external motion planner for the first travel move. const Point &offset = print_object.instances()[print_instance.instance_id].shift; - std::pair this_object_copy(&print_object, offset); - if (m_last_obj_copy != this_object_copy) + GCode::PrintObjectInstance next_instance = {&print_object, int(print_instance.instance_id)}; + if (m_current_instance != next_instance) m_avoid_crossing_perimeters.use_external_mp_once(); - m_last_obj_copy = this_object_copy; + m_current_instance = next_instance; this->set_origin(unscale(offset)); gcode += m_label_objects.start_object(print_instance.print_object.instances()[print_instance.instance_id], GCode::LabelObjects::IncludeName::No); } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 986cf6d92e..91dc8e75c9 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -102,6 +102,15 @@ struct ObjectLayerToPrint coordf_t print_z() const { return (object_layer != nullptr && support_layer != nullptr) ? 0.5 * (object_layer->print_z + support_layer->print_z) : this->layer()->print_z; } }; +struct PrintObjectInstance +{ + const PrintObject *print_object = nullptr; + int instance_idx = -1; + + bool operator==(const PrintObjectInstance &other) const {return print_object == other.print_object && instance_idx == other.instance_idx; } + bool operator!=(const PrintObjectInstance &other) const { return *this == other; } +}; + } // namespace GCode class GCodeGenerator { @@ -126,7 +135,7 @@ public: m_brim_done(false), m_second_layer_things_done(false), m_silent_time_estimator_enabled(false), - m_last_obj_copy(nullptr, Point(std::numeric_limits::max(), std::numeric_limits::max())) + m_current_instance({nullptr, -1}) {} ~GCodeGenerator() = default; @@ -445,8 +454,8 @@ private: bool m_brim_done; // Flag indicating whether the nozzle temperature changes from 1st to 2nd layer were performed. bool m_second_layer_things_done; - // Index of a last object copy extruded. - std::pair m_last_obj_copy; + // Pointer to currently exporting PrintObject and instance index. + GCode::PrintObjectInstance m_current_instance; bool m_silent_time_estimator_enabled;