diff --git a/src/libnest2d/include/libnest2d/selections/firstfit.hpp b/src/libnest2d/include/libnest2d/selections/firstfit.hpp index 47442850a..bc230690b 100644 --- a/src/libnest2d/include/libnest2d/selections/firstfit.hpp +++ b/src/libnest2d/include/libnest2d/selections/firstfit.hpp @@ -119,9 +119,9 @@ public: for(; j < placers.size() && !was_packed && !cancelled(); j++) { result = placers[j].pack(*it, rem(it, store_)); score = result.score(); - score_all_plates = std::accumulate(placers.begin(), placers.begin() + j, score, - [](double sum, const Placer& elem) { return sum + elem.score(); }); - if (this->unfitindicator_) this->unfitindicator_(it->get().name + " bed_id="+std::to_string(j) + ",score=" + std::to_string(score)); + score_all_plates = score; + for (int i = 0; i < placers.size(); i++) { score_all_plates += placers[i].score();} + if (this->unfitindicator_) this->unfitindicator_(it->get().name + " bed_id="+std::to_string(j) + ",score=" + std::to_string(score)+", score_all_plates="+std::to_string(score_all_plates)); if(score >= 0 && score < LARGE_COST_TO_REJECT) { if (bed_id_firstfit == -1) { diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index b507a8530..3b4b68341 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -633,17 +633,24 @@ protected: score += lambda4 * hasRowHeightConflict + lambda4 * hasLidHeightConflict; } else { + int valid_items_cnt = 0; + double height_score = 0; for (int i = 0; i < m_items.size(); i++) { Item& p = m_items[i]; if (!p.is_virt_object) { + valid_items_cnt++; // 高度接近的件尽量摆到一起 - score += (1- std::abs(item.height - p.height) / params.printable_height) + height_score += (1- std::abs(item.height - p.height) / params.printable_height) * norm(pl::distance(ibb.center(), p.boundingBox().center())); //score += LARGE_COST_TO_REJECT * (item.bed_temp - p.bed_temp != 0); - if (!Print::is_filaments_compatible({ item.filament_temp_type,p.filament_temp_type })) + if (!Print::is_filaments_compatible({ item.filament_temp_type,p.filament_temp_type })) { score += LARGE_COST_TO_REJECT; + break; + } } } + if (valid_items_cnt > 0) + score += height_score / valid_items_cnt; } std::set extruder_ids; @@ -664,9 +671,11 @@ protected: } // for layered printing, we want extruder change as few as possible // this has very weak effect, CAN NOT use a large weight + int last_extruder_cnt = extruder_ids.size(); extruder_ids.insert(item.extrude_ids.begin(), item.extrude_ids.end()); + int new_extruder_cnt= extruder_ids.size(); if (!params.is_seq_print) { - score += 1 * std::max(0, ((int) extruder_ids.size() - 1)); + score += 1 * (new_extruder_cnt-last_extruder_cnt); } return std::make_tuple(score, fullbb);