Check mixed filaments against their component filaments' extruders (#16947)

A mixed filament prints with its component filaments, each on its own extruder, but the placement checks resolved it as a filament of its own. On non-Bambu multi-tool printers this could block an object because an extruder that prints none of the components can't reach it, or allow it when a component's extruder can't.

Mixed filaments are now expanded to their components before extruder resolution in the printable area check (GUI and CLI), arrange and the exclusion volume preview, Print::validate(), and brim and support exclusion clipping.

Fixes #16945

(cherry picked from commit 59aa101ea6)
This commit is contained in:
Clifford authored and SoftFever committed 2026-11-01 09:53:53 +08:00
1 parent 9c57223a6f
commit cb63d7933f
9 files changed
+136 -9

No files matched your search

+2 -1
View File
@@ -6650,7 +6650,8 @@ int CLI::run(int argc, char **argv)
// Only check for single-color object
for (size_t j = 0; j < inside_extruders.size(); ++j) {
if (!inside_extruders[j]) {
std::vector<int> filaments = vol->get_extruders();
// A mixed filament prints with its component filaments.
const std::vector<int> filaments = expand_mixed_filament_ids(vol->get_extruders(), m_print_config);
unprintable_filament_ids[j].insert(filaments.begin(), filaments.end());
}
}
+6 -2
View File
@@ -1,5 +1,6 @@
#include "ExclusionVolumeGeometry.hpp"
#include "ExPolygon.hpp"
#include "FilamentMixer.hpp"
#include "Point.hpp"
#include "Polygon.hpp"
#include "PrintConfig.hpp"
@@ -130,9 +131,12 @@ std::vector<size_t> bed_exclusion_physical_extruders(
const bool automatic_mapping_resolved =
!is_auto_filament_map_mode(print.get_filament_map_mode()) || !print.is_BBL_printer() ||
print.get_nozzle_group_result() != nullptr;
bool unresolved = filament_ids.empty();
// A mixed filament prints with its component filaments.
const std::vector<unsigned int> physical_filament_ids = expand_mixed_filaments(
filament_ids, print.config().filament_is_mixed.values, print.config().filament_mixed_components.values);
bool unresolved = physical_filament_ids.empty();
for (const unsigned int filament_id : filament_ids) {
for (const unsigned int filament_id : physical_filament_ids) {
if (grouping) {
if (const auto nozzle = grouping->get_nozzle_for_filament(int(filament_id), layer_id);
nozzle.has_value() && nozzle->extruder_id >= 0 &&
+20
View File
@@ -537,6 +537,26 @@ std::vector<unsigned int> expand_mixed_filaments(
return result;
}
std::vector<int> expand_mixed_filament_ids(const std::vector<int> &filament_ids, const ConfigBase &config)
{
static const std::vector<unsigned char> no_mixed;
static const std::vector<std::string> no_comps;
const auto *is_mixed = config.option<ConfigOptionBools>("filament_is_mixed");
const auto *comps = config.option<ConfigOptionStrings>("filament_mixed_components");
std::vector<unsigned int> ids_0based;
for (const int id : filament_ids)
if (id >= 1)
ids_0based.push_back(static_cast<unsigned int>(id - 1));
ids_0based = expand_mixed_filaments(ids_0based, is_mixed != nullptr ? is_mixed->values : no_mixed,
comps != nullptr ? comps->values : no_comps);
std::vector<int> result;
result.reserve(ids_0based.size());
for (const unsigned int id : ids_0based)
result.push_back(static_cast<int>(id) + 1);
return result;
}
void remap_mixed_components_on_delete(
const std::vector<unsigned char> &is_mixed,
std::vector<std::string> &comp_strs,
+4
View File
@@ -132,6 +132,10 @@ std::vector<unsigned int> expand_mixed_filaments(
const std::vector<unsigned char> &is_mixed,
const std::vector<std::string> &comp_strs);
// Like expand_mixed_filaments(), for 1-based filament ids as models and the GUI number them, with
// the mixed slots read from `config`. Ids below 1 are dropped. Result is sorted and deduplicated.
std::vector<int> expand_mixed_filament_ids(const std::vector<int> &filament_ids, const ConfigBase &config);
// Remap mixed filament component references after a physical filament is deleted.
// del_1based: the 1-based index of the deleted physical filament.
// For each mixed slot:
+4 -1
View File
@@ -199,7 +199,10 @@ static std::optional<BedExclusionCollision> colliding_bed_exclusion(
std::optional<BedExclusionCollision>(BedExclusionCollision{ *first_collision, true }) : std::nullopt;
}
for (const unsigned int filament_id : print_object.printing_extruders()) {
// A mixed filament prints with its component filaments.
const std::vector<unsigned int> filament_ids = expand_mixed_filaments(print_object.printing_extruders(),
print.config().filament_is_mixed.values, print.config().filament_mixed_components.values);
for (const unsigned int filament_id : filament_ids) {
const int resolved_extruder = bed_exclusion_extruder_for_filament(
filament_id, print.get_filament_maps(), print.get_filament_map_mode(), print.is_BBL_printer(),
true, regions_by_extruder.size());
+3 -1
View File
@@ -16,6 +16,7 @@
#include "libslic3r/BuildVolume.hpp"
#include "libslic3r/ExtrusionEntity.hpp"
#include "libslic3r/ExtrusionEntityCollection.hpp"
#include "libslic3r/FilamentMixer.hpp"
#include "libslic3r/Geometry.hpp"
#include "libslic3r/Print.hpp"
#include "libslic3r/SLAPrint.hpp"
@@ -1583,9 +1584,10 @@ bool GLVolumeCollection::check_outside_state(const BuildVolume &build_volume, Mo
//unprintable_filament_ids.resize(inside_extruders.size());
ModelObject *model_object = model_objects[volume->object_idx()];
ModelVolume *model_volume = model_object->volumes[volume->volume_idx()];
// A mixed filament prints with its component filaments.
const std::vector<int> filaments = expand_mixed_filament_ids(model_volume->get_extruders(), plate_project_config);
for (size_t i = 0; i < printable_area_inside_extruders.size(); ++i) {
if (!printable_area_inside_extruders[i]) {
std::vector<int> filaments = model_volume->get_extruders();
unprintable_filament_ids[i].insert(filaments.begin(), filaments.end());
if (object_results) {
std::map<int, std::set<int>>& obj_extruder_filament_maps = objects_unprintable_filaments[model_object];
+7 -4
View File
@@ -3633,15 +3633,18 @@ std::map<int, size_t> PartPlate::get_object_filament_extruders(
filament_ids.emplace(interface_filament);
}
// A mixed filament prints with its component filaments.
std::vector<int> physical_filament_ids =
expand_mixed_filament_ids(std::vector<int>(filament_ids.begin(), filament_ids.end()), g_config);
// Match Orca's normal fallback for an unassigned object.
if (filament_ids.empty())
filament_ids.emplace(1);
if (physical_filament_ids.empty())
physical_filament_ids.emplace_back(1);
const size_t required_filament_count = filament_ids.empty() ? 0 : size_t(*filament_ids.rbegin());
const size_t required_filament_count = size_t(physical_filament_ids.back());
const std::vector<int> filament_map = get_effective_exclusion_filament_maps(
g_config, required_filament_count, extruder_count);
std::map<int, size_t> result;
for (const int filament_id : filament_ids) {
for (const int filament_id : physical_filament_ids) {
if (filament_id <= 0)
continue;
@@ -1,4 +1,5 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_message.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
@@ -21,7 +22,9 @@
#include "libslic3r/GCode/ExclusionVolumeTravelAvoidance.hpp"
#include "libslic3r/GCode/GCodeProcessor.hpp"
#include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/ExclusionVolumeGeometry.hpp"
#include "libslic3r/Print.hpp"
#include "libslic3r/PrintBase.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/Support/SupportCommon.hpp"
#include "libslic3r/Support/SupportLayer.hpp"
@@ -336,6 +339,46 @@ struct SupportPrintFixture
PrintObject &object() { return *print.objects_mutable().front(); }
};
// Three nozzles and filaments, plus filament 4 mixed from filaments 2 and 3. The mixed
// filament's own map entry names extruder 1, which prints neither component. A nonzero
// `colliding_extruder` gets an exclusion volume covering the whole bed.
DynamicPrintConfig mixed_filament_config(FilamentMapMode map_mode, int colliding_extruder = 0)
{
std::vector<std::string> per_extruder(3);
if (colliding_extruder > 0)
per_extruder[colliding_extruder - 1] = "0..256;-100x-100,300x-100,300x300,-100x300";
DynamicPrintConfig config = Test::multifilament_config(4, {
{"filament_is_mixed", "0,0,0,1"},
{"filament_mixed_components", ";;;2,3"},
{"filament_mixed_sublayer_ratios", ";;;0.5,0.5"},
{"filament_mixed_gradient", "0,0,0,0"},
{"filament_mixed_gradient_range", ";;;"},
{"filament_mixed_gradient_curve", ";;;"},
{"filament_mixed_gradient_per_part", "0,0,0,0"},
{"layer_change_gcode", "G92 E0\n"}, // validate() relative-E reset
});
config.set_num_extruders(3);
config.set_key_value("nozzle_diameter", new ConfigOptionFloats(3, 0.4));
config.set_key_value("extruder_offset", new ConfigOptionPoints(3, Vec2d::Zero()));
config.set_key_value("extruder_printable_height", new ConfigOptionFloatsNullable(3, 256.0));
config.set_key_value("bed_exclude_volume_mode", new ConfigOptionEnum<BedExcludeVolumeMode>(BedExcludeVolumeMode::PerExtruder));
config.set_key_value("extruder_bed_exclude_volumes", new ConfigOptionStrings(per_extruder));
config.set_key_value("filament_map_mode", new ConfigOptionEnum<FilamentMapMode>(map_mode));
config.set_key_value("filament_map", new ConfigOptionInts{1, 2, 3, 1});
return config;
}
// Validate a cube that prints with the mixed filament 4 only.
StringObjectException validate_mixed_filament_cube(FilamentMapMode map_mode, int colliding_extruder)
{
const std::vector<std::vector<ConfigBase::SetDeserializeItem>> object_overrides { { { "extruder", 4 } } };
Print print;
Model model;
Test::init_print({ Test::cube(20.) }, print, model, mixed_filament_config(map_mode, colliding_extruder), &object_overrides);
return print.validate();
}
} // namespace
TEST_CASE("Path checker ignores clear motions and motions outside the active Z slab", "[ExclusionVolume][GCode]")
@@ -810,3 +853,33 @@ TEST_CASE("Support trimming applies the correct nozzle mask to every polygon cat
CHECK_FALSE(polygons_cover(*base.overhang_polygons, -4.0, -4.0));
CHECK_FALSE(polygons_cover(*base.enforcer_polygons, -4.0, -4.0));
}
TEST_CASE("A mixed filament's exclusion extruders are its component filaments' extruders", "[ExclusionVolume][MultiNozzle][MixedFilament]")
{
const FilamentMapMode map_mode = GENERATE(fmmAutoForFlush, fmmManual);
CAPTURE(map_mode);
Print print;
Model model;
Test::init_print({ Test::cube(20.) }, print, model, mixed_filament_config(map_mode));
// Filament 4 (id 3) mixes filaments 2 and 3, which print on extruders 2 and 3 (ids 1 and 2).
CHECK(bed_exclusion_physical_extruders(print, {3}, 3, 0) == std::vector<size_t>{1, 2});
}
TEST_CASE("Print validation accepts a mixed filament when only an extruder printing neither component collides", "[ExclusionVolume][Print][MultiNozzle][MixedFilament]")
{
const FilamentMapMode map_mode = GENERATE(fmmAutoForFlush, fmmManual);
CAPTURE(map_mode);
// Extruder 1 prints neither filament 2 nor filament 3.
CHECK(validate_mixed_filament_cube(map_mode, 1).string.empty());
}
TEST_CASE("Print validation rejects a mixed filament when the extruder of one of its components collides", "[ExclusionVolume][Print][MultiNozzle][MixedFilament]")
{
const FilamentMapMode map_mode = GENERATE(fmmAutoForFlush, fmmManual);
const int colliding_extruder = GENERATE(2, 3);
CAPTURE(map_mode, colliding_extruder);
// Filaments 2 and 3, the components of filament 4, print on extruders 2 and 3.
CHECK_THAT(validate_mixed_filament_cube(map_mode, colliding_extruder).string,
Catch::Matchers::ContainsSubstring("extruder " + std::to_string(colliding_extruder)));
}
+17
View File
@@ -65,6 +65,23 @@ TEST_CASE("expand_mixed_filaments replaces mixed slots with their components", "
}
}
TEST_CASE("expand_mixed_filament_ids replaces 1-based mixed filaments with their components", "[FilamentMixer]")
{
// Filament 4 is a mix of filaments 2 and 3.
DynamicPrintConfig cfg;
cfg.set_key_value("filament_is_mixed", new ConfigOptionBools({false, false, false, true}));
cfg.set_key_value("filament_mixed_components", new ConfigOptionStrings({"", "", "", "2,3"}));
REQUIRE(expand_mixed_filament_ids({4}, cfg) == std::vector<int>{2, 3});
SECTION("Physical filaments pass through, ids below 1 are dropped, result is sorted and deduplicated") {
REQUIRE(expand_mixed_filament_ids({4, 0, 3, 1}, cfg) == std::vector<int>{1, 2, 3});
}
SECTION("A config without mixed filaments leaves the ids as they are") {
REQUIRE(expand_mixed_filament_ids({4, 1}, DynamicPrintConfig()) == std::vector<int>{1, 4});
}
}
TEST_CASE("belt purge tower island count ignores virtual mixed slots", "[FilamentMixer][belt]")
{
// Regression for the "extra purge tower" on a belt printer with a mixed