From ca34800cade4ddef1c8a31c76ec3b9189ad9ada1 Mon Sep 17 00:00:00 2001 From: "weizhen.xie" Date: Tue, 1 Jul 2025 20:25:19 +0800 Subject: [PATCH] =?UTF-8?q?ENH=EF=BC=9AObject=20skipping=20supports=20skip?= =?UTF-8?q?ping=20flushing=20of=20filament=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jira:[STUDIO-12781] Change-Id: Ia21d07b0ef107867cce55631d99bd03caebd6387 (cherry picked from commit d74849d499078f87d14282e92f48b2c02355d96c) --- .../BBL/machine/Bambu Lab H2D 0.4 nozzle.json | 1 + .../machine/Bambu Lab H2D Pro 0.4 nozzle.json | 1 + .../BBL/machine/Bambu Lab H2S 0.4 nozzle.json | 1 + .../BBL/machine/Bambu Lab P2S 0.4 nozzle.json | 1 + .../BBL/machine/fdm_machine_common.json | 1 + src/libslic3r/GCode.cpp | 84 ++++++++++++++----- src/libslic3r/GCode.hpp | 1 + src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 3 + src/libslic3r/PrintConfig.hpp | 1 + 10 files changed, 73 insertions(+), 23 deletions(-) diff --git a/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json index 3fdeccb456..11890c1026 100644 --- a/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json @@ -98,6 +98,7 @@ "10" ], "support_chamber_temp_control": "1", + "support_object_skip_flush": "1", "wrapping_exclude_area": [ "145x310", "256x310", diff --git a/resources/profiles/BBL/machine/Bambu Lab H2D Pro 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab H2D Pro 0.4 nozzle.json index 038d55afed..14809d44bd 100644 --- a/resources/profiles/BBL/machine/Bambu Lab H2D Pro 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab H2D Pro 0.4 nozzle.json @@ -102,6 +102,7 @@ "10" ], "support_chamber_temp_control": "1", + "support_object_skip_flush": "1", "wrapping_exclude_area": [ "145x310", "256x310", diff --git a/resources/profiles/BBL/machine/Bambu Lab H2S 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab H2S 0.4 nozzle.json index a54ab1ab85..f0b57c403b 100644 --- a/resources/profiles/BBL/machine/Bambu Lab H2S 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab H2S 0.4 nozzle.json @@ -209,6 +209,7 @@ "18" ], "support_chamber_temp_control": "1", + "support_object_skip_flush": "1", "wipe_distance": [ "2", "2" diff --git a/resources/profiles/BBL/machine/Bambu Lab P2S 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab P2S 0.4 nozzle.json index 530cef1647..9af66e3838 100644 --- a/resources/profiles/BBL/machine/Bambu Lab P2S 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab P2S 0.4 nozzle.json @@ -213,6 +213,7 @@ "18", "18" ], + "support_object_skip_flush": "1", "wipe_distance": [ "2", "2" diff --git a/resources/profiles/BBL/machine/fdm_machine_common.json b/resources/profiles/BBL/machine/fdm_machine_common.json index c04004abcf..e33d6b9f9b 100644 --- a/resources/profiles/BBL/machine/fdm_machine_common.json +++ b/resources/profiles/BBL/machine/fdm_machine_common.json @@ -140,6 +140,7 @@ "single_extruder_multi_material": "1", "support_air_filtration": "0", "support_chamber_temp_control": "0", + "support_object_skip_flush": "0", "wipe": [ "1" ], diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index ad1094d40c..05bfa2570d 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -748,8 +748,6 @@ static std::vector get_path_of_change_filament(const Print& print) gcode += gcodegen.unretract(); } - // BBS: if needed, write the gcode_label_objects_end then priming tower, if the retract, didn't did it. - gcodegen.m_writer.add_object_end_labels(gcode); double current_z = gcodegen.writer().get_position().z(); if (z == -1.) // in case no specific z was provided, print at current_z pos @@ -761,6 +759,7 @@ static std::vector get_path_of_change_filament(const Print& print) } // Process the end filament gcode. + bool add_change_filament_624 = false; std::string end_filament_gcode_str; if (gcodegen.writer().filament() != nullptr) { // Process the custom filament_end_gcode in case of single_extruder_multi_material. @@ -769,7 +768,12 @@ static std::vector get_path_of_change_filament(const Print& print) if (gcodegen.writer().filament() != nullptr && !filament_end_gcode.empty()) { DynamicConfig config; config.set_key_value("layer_num", new ConfigOptionInt(gcodegen.m_layer_index)); - end_filament_gcode_str = gcodegen.placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_filament_id, &config); + if (!gcodegen.m_filament_instances_code.empty()) { + end_filament_gcode_str += ("M624 " + gcodegen.m_filament_instances_code + "\n"); + gcodegen.m_filament_instances_code = ""; + add_change_filament_624 = true; + } + end_filament_gcode_str += gcodegen.placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_filament_id, &config); check_add_eol(end_filament_gcode_str); } } @@ -788,6 +792,10 @@ static std::vector get_path_of_change_filament(const Print& print) std::string toolchange_retract_str = gcodegen.retract(tcr.is_tool_change && !is_nozzle_change, false, auto_lift_type); check_add_eol(toolchange_retract_str); + //BBS: if needed, write the gcode_label_objects_end then priming tower, if the retract, didn't did it. + std::string object_end_label_temp; + gcodegen.m_writer.add_object_end_labels(object_end_label_temp); + // Process the custom change_filament_gcode. If it is empty, provide a simple Tn command to change the filament. // Otherwise, leave control to the user completely. std::string change_filament_gcode = gcodegen.config().change_filament_gcode.value; @@ -813,8 +821,9 @@ static std::vector get_path_of_change_filament(const Print& print) end_filament_gcode_str = nozzle_change_gcode_trans + end_filament_gcode_str; } - end_filament_gcode_str = toolchange_retract_str + end_filament_gcode_str; + end_filament_gcode_str = toolchange_retract_str + object_end_label_temp + end_filament_gcode_str; + std::string wipe_next_start_point_str; bool need_travel_after_change_filament_gcode = false; // travel need be after the filament changed to get the correct "m_curr_extruder_id" if (! change_filament_gcode.empty()) { DynamicConfig config; @@ -952,7 +961,7 @@ static std::vector get_path_of_change_filament(const Print& print) if (!is_used_travel_avoid_perimeter) { std::string start_pos_str = gcodegen.travel_to(wipe_tower_point_to_object_point(gcodegen, tool_change_start_pos + plate_origin_2d), erMixed, "Move to start pos"); check_add_eol(start_pos_str); - toolchange_gcode_str += start_pos_str; + wipe_next_start_point_str = start_pos_str; } else { // BBS:change travel_path Vec3f gcode_last_pos; @@ -980,7 +989,14 @@ static std::vector get_path_of_change_filament(const Print& print) } std::string travel_to_wipe_tower_gcode; Polyline travel_polyline = generate_path_to_wipe_tower(gcode_last_pos2d_object, start_wipe_pos, avoid_bbx, printer_bbx); - for (const auto &p : travel_polyline.points) { + + for (size_t i = 0; i < travel_polyline.points.size(); ++i) { + const auto &p = travel_polyline.points[i]; + if (i == travel_polyline.points.size() - 1) { + wipe_next_start_point_str = gcodegen.travel_to(p, erMixed, "Move to start pos"); + check_add_eol(wipe_next_start_point_str); + break; + } travel_to_wipe_tower_gcode += gcodegen.travel_to(p, erMixed, "Move to start pos"); check_add_eol(travel_to_wipe_tower_gcode); } @@ -1007,10 +1023,14 @@ static std::vector get_path_of_change_filament(const Print& print) DynamicConfig config; config.set_key_value("filament_extruder_id", new ConfigOptionInt(new_filament_id)); start_filament_gcode_str = gcodegen.placeholder_parser_process("filament_start_gcode", filament_start_gcode, new_filament_id, &config); + if (add_change_filament_624) { + start_filament_gcode_str += "M625\n"; + add_change_filament_624 = false; + } check_add_eol(start_filament_gcode_str); } - start_filament_gcode_str = start_filament_gcode_str + toolchange_unretract_str; + start_filament_gcode_str = start_filament_gcode_str + wipe_next_start_point_str + toolchange_unretract_str; // Insert the end filament, toolchange, and start filament gcode into the generated gcode. DynamicConfig config; @@ -4645,6 +4665,7 @@ LayerResult GCode::process_layer( } // for objects std::map> filament_to_print_instances; + std::map> filament_to_print_instances_temp; { for (unsigned int filament_id : layer_tools.extruders) { auto objects_by_extruder_it = by_extruder.find(filament_id); @@ -4653,21 +4674,24 @@ LayerResult GCode::process_layer( bool has_prime_tower = print.config().enable_prime_tower && print.extruders().size() > 1 && ((print.config().print_sequence == PrintSequence::ByLayer && print.config().print_order == PrintOrder::Default) || (print.config().print_sequence == PrintSequence::ByObject && print.objects().size() == 1)); + + int plate_idx = print.get_plate_index(); + Point wt_pos(print.config().wipe_tower_x.get_at(plate_idx), print.config().wipe_tower_y.get_at(plate_idx)); + + std::vector &objects_by_extruder = objects_by_extruder_it->second; + std::vector print_objects; + for (int obj_idx = 0; obj_idx < objects_by_extruder.size(); obj_idx++) { + auto &object_by_extruder = objects_by_extruder[obj_idx]; + if (object_by_extruder.islands.empty() && (object_by_extruder.support == nullptr || object_by_extruder.support->empty())) continue; + + print_objects.push_back(print.get_object(obj_idx)); + } + + std::vector new_ordering = chain_print_object_instances(print_objects, &wt_pos); + std::reverse(new_ordering.begin(), new_ordering.end()); + filament_to_print_instances_temp[filament_id] = sort_print_object_instances(objects_by_extruder_it->second, layers, &new_ordering, single_object_instance_idx); + if (has_prime_tower) { - int plate_idx = print.get_plate_index(); - Point wt_pos(print.config().wipe_tower_x.get_at(plate_idx), print.config().wipe_tower_y.get_at(plate_idx)); - - std::vector &objects_by_extruder = objects_by_extruder_it->second; - std::vector print_objects; - for (int obj_idx = 0; obj_idx < objects_by_extruder.size(); obj_idx++) { - auto &object_by_extruder = objects_by_extruder[obj_idx]; - if (object_by_extruder.islands.empty() && (object_by_extruder.support == nullptr || object_by_extruder.support->empty())) continue; - - print_objects.push_back(print.get_object(obj_idx)); - } - - std::vector new_ordering = chain_print_object_instances(print_objects, &wt_pos); - std::reverse(new_ordering.begin(), new_ordering.end()); filament_to_print_instances[filament_id] = sort_print_object_instances(objects_by_extruder_it->second, layers, &new_ordering, single_object_instance_idx); } else { filament_to_print_instances[filament_id] = sort_print_object_instances(objects_by_extruder_it->second, layers, ordering, single_object_instance_idx); @@ -4782,6 +4806,12 @@ LayerResult GCode::process_layer( gcode += generate_skirt(print, print.skirt(), Point(0, 0), layer.object()->config().skirt_start_angle, layer_tools, layer, extruder_id); + if (m_enable_exclude_object && print.config().support_object_skip_flush.value) { + std::vector filament_instances_id; + for (InstanceToPrint &instance : filament_to_print_instances_temp[extruder_id]) filament_instances_id.emplace_back(instance.label_object_id); + m_filament_instances_code = _encode_label_ids_to_base64(filament_instances_id); + } + std::string gcode_toolchange; if (has_wipe_tower) { if (!m_wipe_tower->is_empty_wipe_tower_gcode(*this, extruder_id, extruder_id == layer_tools.extruders.back())) { @@ -7171,6 +7201,7 @@ std::string GCode::set_extruder(unsigned int new_filament_id, double print_z, bo if (by_object) m_writer.add_object_change_labels(gcode); + bool add_change_filament_624 = false; if (m_writer.filament() != nullptr) { // Process the custom filament_end_gcode. set_extruder() is only called if there is no wipe tower // so it should not be injected twice. @@ -7182,7 +7213,12 @@ std::string GCode::set_extruder(unsigned int new_filament_id, double print_z, bo config.set_key_value("layer_z", new ConfigOptionFloat(m_writer.get_position().z() - m_config.z_offset.value)); config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z)); config.set_key_value("filament_extruder_id", new ConfigOptionInt(int(get_extruder_id(old_filament_id)))); - gcode += placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_filament_id, &config); + if (!m_filament_instances_code.empty()) { + gcode += ("M624 " + m_filament_instances_code + "\n"); + gcode += placeholder_parser_process("filament_end_gcode", filament_end_gcode, old_filament_id, &config); + m_filament_instances_code = ""; + add_change_filament_624 = true; + } check_add_eol(gcode); } } @@ -7393,6 +7429,10 @@ std::string GCode::set_extruder(unsigned int new_filament_id, double print_z, bo config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z)); config.set_key_value("filament_extruder_id", new ConfigOptionInt(int(new_filament_id))); gcode += this->placeholder_parser_process("filament_start_gcode", filament_start_gcode, new_filament_id, &config); + if (add_change_filament_624) { + gcode += "M625\n"; + add_change_filament_624 = false; + } check_add_eol(gcode); } // Set the new extruder to the operating temperature. diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 5e8dc8bdd1..2827f9c2ad 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -630,6 +630,7 @@ private: coordf_t m_nominal_z; bool m_need_change_layer_lift_z = false; int m_start_gcode_filament = -1; + std::string m_filament_instances_code; std::set m_initial_layer_extruders; std::vector> m_sorted_layer_filaments; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 4fded0d1a0..a7320c65c4 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1013,7 +1013,7 @@ static std::vector s_Preset_printer_options { "printhost_cafile","printhost_port","printhost_authorization_type", "printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", "thumbnails", "thumbnails_format", "use_relative_e_distances", "extruder_type", "use_firmware_retraction", "printer_notes", - "grab_length", "physical_extruder_map", + "grab_length", "support_object_skip_flush", "physical_extruder_map", "cooling_tube_retraction", "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming", "z_offset", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 6a460bc199..8848302e5c 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2365,6 +2365,9 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat { 0. }); + def = this->add("support_object_skip_flush", coBool); + def->set_default_value(new ConfigOptionBool(false)); + def = this->add("bed_temperature_formula", coEnum); def->label = L("Bed temperature type"); def->tooltip = L("This option determines how the bed temperature is set during slicing: based on the temperature of the first filament or the highest temperature of the printed filaments."); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 3125e654c7..269fba47fa 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1259,6 +1259,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionInts, filament_map)) //((ConfigOptionInts, filament_extruder_id)) ((ConfigOptionStrings, filament_extruder_variant)) + ((ConfigOptionBool, support_object_skip_flush)) ((ConfigOptionEnum, bed_temperature_formula)) ((ConfigOptionInts, physical_extruder_map)) ((ConfigOptionIntsNullable, nozzle_flush_dataset))