diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 2b664d2314..3b84239760 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -3396,6 +3396,14 @@ void ModelVolume::convert_from_meters() this->source.is_converted_from_meters = true; } +bool ModelVolume::is_mm_painted_everywhere() const +{ + const TriangleSelector::TriangleSplittingData &data = this->mmu_segmentation_facets.get_data(); + // Unpainted facets are not stored, and the unpainted parts of a split facet are stored as NONE. + return data.triangles_to_split.size() == this->mesh().its.indices.size() && + !data.used_states[static_cast(EnforcerBlockerType::NONE)]; +} + // Orca: Implement prusa's filament shrink compensation approach // Returns 0-based indices of extruders painted by multi-material painting gizmo. std::vector ModelVolume::get_extruders_from_multi_material_painting() const { diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index d77100753a..070344afb9 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1195,6 +1195,8 @@ public: bool is_fdm_support_painted() const { return !this->supported_facets.empty(); } bool is_seam_painted() const { return !this->seam_facets.empty(); } bool is_mm_painted() const { return !this->mmu_segmentation_facets.empty(); } + // Whether multi-material painting covers every facet. + bool is_mm_painted_everywhere() const; bool is_fuzzy_skin_painted() const { return !this->fuzzy_skin_facets.empty(); } bool is_texture_displacement_painted() const { return !this->texture_displacement_facets_all_empty(); } bool is_any_painted() const { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 4dbcffef2f..eb1ac1726d 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2521,7 +2521,25 @@ StringObjectException Print::validate(std::vector *warnin // spiral vase cannot print. const auto &is_mixed = m_config.filament_is_mixed.values; for (const PrintObject *object : m_objects) { - const auto used_filament_ids = object->object_extruders(); + auto used_filament_ids = object->object_extruders(); + // Painted all over, the object prints only its painted filaments, unless the segmented region + // max width or interlocking depth limits the paint to a band and fills the rest with its own filament. + // Beam interlocking turns that band off. + const PrintObjectConfig &object_config = object->config(); + const ModelVolumePtrs &volumes = object->model_object()->volumes; + if ((object_config.interlocking_beam.value || + (object_config.mmu_segmented_region_max_width.value == 0. && + object_config.mmu_segmented_region_interlocking_depth.value == 0.)) && + std::all_of(volumes.begin(), volumes.end(), [](const ModelVolume *volume) { + return !volume->is_model_part() || volume->is_mm_painted_everywhere(); + })) { + used_filament_ids.clear(); + for (const ModelVolume *volume : volumes) + if (volume->is_model_part()) + for (size_t filament_id : volume->get_extruders_from_multi_material_painting()) + used_filament_ids.push_back(static_cast(filament_id)); + sort_remove_duplicates(used_filament_ids); + } if (used_filament_ids.size() > 1 || std::any_of(used_filament_ids.begin(), used_filament_ids.end(), [&is_mixed](unsigned int filament_id) { return filament_id < is_mixed.size() && is_mixed[filament_id]; diff --git a/tests/fff_print/test_multifilament.cpp b/tests/fff_print/test_multifilament.cpp index 6948b828c8..82f89891e8 100644 --- a/tests/fff_print/test_multifilament.cpp +++ b/tests/fff_print/test_multifilament.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "libslic3r/GCode/GCodeProcessor.hpp" #include "libslic3r/GCodeReader.hpp" #include "libslic3r/TriangleSelector.hpp" @@ -87,6 +88,49 @@ TEST_CASE("Painted filaments slice when the display palette is shorter than the REQUIRE(second_filament_present); } +TEST_CASE("Spiral vase mode prints a model painted all over with a filament other than its own", "[MultiFilament]") +{ + // Painting the whole cube leaves only filament 2. Painting half of it, or limiting the paint to a band near the + // walls, leaves two filaments, which spiral vase can't print. Beam interlocking turns the band off. + const bool all_over = GENERATE(true, false); + const std::string band_key = GENERATE("", "mmu_segmented_region_max_width", "mmu_segmented_region_interlocking_depth"); + const bool beam = GENERATE(false, true); + CAPTURE(all_over, band_key, beam); + auto config = multifilament_config(2, { + { "spiral_mode", 1 }, + { "enable_prime_tower", 0 }, + { "skirt_loops", 0 }, + { "brim_type", "no_brim" }, + { "gcode_comments", 1 }, + { "layer_change_gcode", "G92 E0" }, + { "interlocking_beam", beam }, + }); + if (!band_key.empty()) + config.set_deserialize_strict(band_key, "1"); + Print print; + Model model; + init_print({cube(20)}, print, model, config); + ModelVolume *volume = model.objects.front()->volumes.front(); + TriangleSelector selector(volume->mesh()); + const int facets = int(volume->mesh().its.indices.size()); + for (int facet = 0; facet < (all_over ? facets : facets / 2); ++facet) + selector.set_facet(facet, EnforcerBlockerType::Extruder2); + REQUIRE(volume->mmu_segmentation_facets.set(selector)); + CHECK(volume->is_mm_painted_everywhere() == all_over); + print.apply(model, config); + + const std::string error = print.validate().string; + if (!all_over || (!band_key.empty() && !beam)) { + CHECK_THAT(error, Catch::Matchers::ContainsSubstring("more than one material")); + return; + } + INFO(error); + REQUIRE(error.empty()); + const std::string gcode = Test::gcode(print); + CHECK(tools_for_role(gcode, "perimeter") == std::set{ 1 }); + CHECK(tools_for_role(gcode, "infill") == std::set{ 1 }); +} + // X where the nozzle sits while each tagged _WAIT_FOR_TEMP_ON_WIPE_TOWER M109 blocks: // the nearest preceding G1 carrying an X (the park travel emitted just before the wait). static std::vector wait_park_xs(const std::string& gcode)