diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp index 7cc53d8b0a0..2624bc038e9 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp @@ -60,6 +60,7 @@ std::string find_closest_color_preset_by_vendor_and_type(const Slic3r::PresetCol unsigned int target = parse_color(color_rgba); + // Pass 1: compatible + visible presets (ideal match) for (const auto& p : filaments.get_presets()) { if (!(p.is_visible && p.is_compatible)) continue; if (filaments.get_preset_base(p) != &p) continue; @@ -76,6 +77,25 @@ std::string find_closest_color_preset_by_vendor_and_type(const Slic3r::PresetCol best_match_id = p.filament_id; } } + if (!best_match_id.empty()) return best_match_id; + + // Pass 2: fallback — any base preset matching vendor+type, even if not compatible/instantiatable. + // Covers vendors like Elegoo that have a @base preset but no printer-specific variant for this printer. + for (const auto& p : filaments.get_presets()) { + if (p.config.opt_string("filament_vendor", 0u) != vendor_name) continue; + if (p.config.opt_string("filament_type", 0u) != filament_type) continue; + if (p.filament_id.empty()) continue; + + unsigned int pc = parse_color(p.config.opt_string("default_filament_colour", 0u)); + int dr = ((target ) & 0xff) - ((pc ) & 0xff); + int dg = ((target >> 8) & 0xff) - ((pc >> 8) & 0xff); + int db = ((target >> 16) & 0xff) - ((pc >> 16) & 0xff); + unsigned int distance = dr * dr + dg * dg + db * db; + if (distance < (unsigned int)best_color_distance) { + best_color_distance = (int)distance; + best_match_id = p.filament_id; + } + } return best_match_id; }