Size painted segmentation from the filament count, not the color palette (#15998)

multi_material_segmentation_by_painting sized its per-filament output from filament_colour, but apply_mm_segmentation reads one entry per filament_diameter. When the palette was shorter than the filament list, slicing an object painted with a filament that had no color read past the end and crashed. Size it from filament_diameter instead.

Adds a regression test that paints one side of a cube with filament 2 while filament_colour has one entry.
This commit is contained in:
Andrew Gribben authored and GitHub committed 2026-10-26 13:36:37 -05:00
1 parent ab24043937
commit 21d2856429
2 files changed
+33 -1

No files matched your search

+2 -1
View File
@@ -2469,7 +2469,8 @@ std::vector<std::vector<ExPolygons>> segmentation_by_painting(const PrintObject
// Returns multi-material segmentation based on painting in multi-material segmentation gizmo
std::vector<std::vector<ExPolygons>> multi_material_segmentation_by_painting(const PrintObject &print_object, const std::function<void()> &throw_on_cancel_callback) {
const size_t num_facets_states = print_object.print()->config().filament_colour.size() + 1;
// apply_mm_segmentation() reads one entry per filament_diameter, and filament_colour can be shorter.
const size_t num_facets_states = print_object.print()->config().filament_diameter.size() + 1;
const float max_width = float(print_object.config().mmu_segmented_region_max_width.value);
const float interlocking_depth = float(print_object.config().mmu_segmented_region_interlocking_depth.value);
const bool interlocking_beam = print_object.config().interlocking_beam.value;
+31
View File
@@ -7,6 +7,8 @@
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "libslic3r/GCode/GCodeProcessor.hpp"
#include "libslic3r/GCodeReader.hpp"
#include "libslic3r/TriangleSelector.hpp"
#include "libslic3r/MultiMaterialSegmentation.hpp"
#include "test_helpers.hpp"
#include "test_utils.hpp"
@@ -54,6 +56,35 @@ static std::set<int> tools_for_role(const std::string& gcode, const std::string&
return tools;
}
TEST_CASE("Painted filaments slice when the display palette is shorter than the filament list", "[MultiFilament][Regression]")
{
auto config = multifilament_config(2, {
{ "filament_colour", "#FF0000" },
{ "enable_prime_tower", "0" },
{ "gcode_comments", "1" }
});
Print print;
Model model;
init_print({cube(10)}, print, model, config);
auto *volume = model.objects.front()->volumes.front();
TriangleSelector selector(volume->mesh());
// Paint one side with the second filament, leaving the rest on the first.
selector.set_facet(4, EnforcerBlockerType::Extruder2);
selector.set_facet(5, EnforcerBlockerType::Extruder2);
REQUIRE(volume->mmu_segmentation_facets.set(selector));
print.apply(model, config);
PrintObject *object = print.objects_mutable().front();
object->slice();
const auto segmentation = multi_material_segmentation_by_painting(*object, [] {});
REQUIRE_FALSE(segmentation.empty());
bool second_filament_present = false;
for (const auto &layer : segmentation) {
REQUIRE(layer.size() == 2);
second_filament_present |= !layer[1].empty();
}
REQUIRE(second_filament_present);
}
// 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<double> wait_park_xs(const std::string& gcode)