From fd55cc77d32b688fd9de48545d29babe4a137410 Mon Sep 17 00:00:00 2001 From: Harry Loud Date: Thu, 16 Jul 2026 16:07:45 +0100 Subject: [PATCH] Make support generation exclusion-volume aware --- src/libslic3r/Brim.cpp | 44 +------- src/libslic3r/ExclusionVolumeGeometry.cpp | 65 +++++++++++ src/libslic3r/ExclusionVolumeGeometry.hpp | 24 +++++ src/libslic3r/GCode.cpp | 21 +++- src/libslic3r/GCode.hpp | 3 +- src/libslic3r/Print.cpp | 68 +++++++++++- src/libslic3r/Print.hpp | 4 + src/libslic3r/Support/SupportCommon.cpp | 119 +++++++++++++++++++++ src/libslic3r/Support/SupportCommon.hpp | 26 +++++ src/libslic3r/Support/SupportMaterial.cpp | 4 + src/libslic3r/Support/TreeModelVolumes.cpp | 32 +++--- src/libslic3r/Support/TreeSupport3D.cpp | 34 +++++- 12 files changed, 376 insertions(+), 68 deletions(-) diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp index 9fb1ccf519..ffe355ea50 100644 --- a/src/libslic3r/Brim.cpp +++ b/src/libslic3r/Brim.cpp @@ -8,10 +8,12 @@ #include "PrintConfig.hpp" #include "MaterialType.hpp" #include "Model.hpp" +#include "Support/SupportCommon.hpp" #include #include #include #include +#include #include #include @@ -26,37 +28,6 @@ namespace Slic3r { -static std::vector brim_physical_extruders( - const Print &print, - const size_t filament_id, - const size_t physical_extruder_count) -{ - if (physical_extruder_count == 0) - return {}; - - if (const auto grouping = print.get_layered_nozzle_group_result()) { - if (const auto nozzle = grouping->get_nozzle_for_filament(int(filament_id), 0); - nozzle.has_value() && nozzle->extruder_id >= 0 && - size_t(nozzle->extruder_id) < physical_extruder_count) - return { size_t(nozzle->extruder_id) }; - } - - 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; - const int resolved = bed_exclusion_extruder_for_filament( - filament_id, print.get_filament_maps(), print.get_filament_map_mode(), print.is_BBL_printer(), - automatic_mapping_resolved, physical_extruder_count); - if (resolved >= 0) - return { size_t(resolved) }; - - // Generated geometry must remain safe if a late automatic assignment has - // not selected a physical nozzle yet. - std::vector candidates(physical_extruder_count); - std::iota(candidates.begin(), candidates.end(), size_t(0)); - return candidates; -} - static coord_t brim_exclusion_clearance(const Flow &flow) { const coord_t width_spacing_delta = std::max(0, flow.scaled_width() - flow.scaled_spacing()); @@ -470,10 +441,6 @@ static ExPolygons outer_inner_brim_area(const Print& print, get_bed_excluded_regions_by_extruder(print.config()); const double first_layer_top_z = std::max(0.0, print.skirt_first_layer_height()); const coord_t exclusion_clearance = brim_exclusion_clearance(flow); - std::vector combined_brim_physical_extruders; - if (combine_object_brims(print) && !printExtruders.empty()) - combined_brim_physical_extruders = brim_physical_extruders( - print, printExtruders.front(), exclusion_regions_by_extruder.size()); ExPolygons brim_area; ExPolygons no_brim_area; @@ -690,11 +657,8 @@ static ExPolygons outer_inner_brim_area(const Print& print, std::vector object_physical_extruders; if (iter != objPrintVec.end() && iter->second > 0) { - object_physical_extruders = brim_physical_extruders( - print, size_t(iter->second - 1), exclusion_regions_by_extruder.size()); - object_physical_extruders.insert( - object_physical_extruders.end(), - combined_brim_physical_extruders.begin(), combined_brim_physical_extruders.end()); + object_physical_extruders = bed_exclusion_physical_extruders( + print, { iter->second - 1 }, exclusion_regions_by_extruder.size(), 0); for (const size_t extruder_id : object_physical_extruders) { if (extruder_id >= extruder_unprintable_area.size()) continue; diff --git a/src/libslic3r/ExclusionVolumeGeometry.cpp b/src/libslic3r/ExclusionVolumeGeometry.cpp index 32365b8d41..af1bf25091 100644 --- a/src/libslic3r/ExclusionVolumeGeometry.cpp +++ b/src/libslic3r/ExclusionVolumeGeometry.cpp @@ -1,8 +1,10 @@ #include "ExclusionVolumeGeometry.hpp" #include "ClipperUtils.hpp" +#include "Print.hpp" #include +#include #include namespace Slic3r { @@ -89,4 +91,67 @@ ExPolygons active_bed_exclusion_footprints( return union_active_footprints(std::move(footprints), clearance); } +std::vector bed_exclusion_physical_extruders( + const Print &print, + const std::vector &filament_ids, + const size_t physical_extruder_count, + const int layer_id) +{ + if (physical_extruder_count == 0) + return {}; + + std::vector result; + const auto grouping = print.get_layered_nozzle_group_result(); + 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(); + + for (const unsigned int filament_id : 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 && + size_t(nozzle->extruder_id) < physical_extruder_count) { + result.emplace_back(size_t(nozzle->extruder_id)); + continue; + } + } + + const int resolved = bed_exclusion_extruder_for_filament( + filament_id, print.get_filament_maps(), print.get_filament_map_mode(), print.is_BBL_printer(), + automatic_mapping_resolved, physical_extruder_count); + if (resolved >= 0) + result.emplace_back(size_t(resolved)); + else + unresolved = true; + } + + std::sort(result.begin(), result.end()); + result.erase(std::unique(result.begin(), result.end()), result.end()); + if (!unresolved && !result.empty()) + return result; + + result.resize(physical_extruder_count); + std::iota(result.begin(), result.end(), size_t(0)); + return result; +} + +ExPolygons active_bed_exclusion_footprints_for_object( + const PrintObject &object, + const std::vector> ®ions_by_extruder, + const std::vector &physical_extruders, + const double z_min, + const double z_max, + const coord_t clearance) +{ + ExPolygons result; + for (const PrintInstance &instance : object.instances()) { + const Point instance_shift = instance.shift_without_plate_offset(); + const Point shift(-instance_shift.x(), -instance_shift.y()); + expolygons_append(result, active_bed_exclusion_footprints( + regions_by_extruder, physical_extruders, z_min, z_max, shift, clearance)); + } + return result.empty() ? ExPolygons{} : union_ex(result); +} + } // namespace Slic3r diff --git a/src/libslic3r/ExclusionVolumeGeometry.hpp b/src/libslic3r/ExclusionVolumeGeometry.hpp index b72868d76b..cbf7140b85 100644 --- a/src/libslic3r/ExclusionVolumeGeometry.hpp +++ b/src/libslic3r/ExclusionVolumeGeometry.hpp @@ -9,6 +9,9 @@ namespace Slic3r { +class Print; +class PrintObject; + bool bed_exclusion_z_ranges_overlap(double first_min, double first_max, double second_min, double second_max); // Return the union of exclusion footprints intersecting the requested extrusion @@ -30,4 +33,25 @@ ExPolygons active_bed_exclusion_footprints( const Point &translation = Point(0, 0), coord_t clearance = 0); +// Resolve logical filaments to every physical extruder which may print them. +// An unresolved automatic mapping deliberately returns every physical +// extruder, keeping generated geometry conservative until tool assignment is +// known. +std::vector bed_exclusion_physical_extruders( + const Print &print, + const std::vector &filament_ids, + size_t physical_extruder_count, + int layer_id = -1); + +// Exclusion areas are stored in bed coordinates while generated support is +// shared in PrintObject coordinates. Return the conservative union transformed +// for every instance of the object. +ExPolygons active_bed_exclusion_footprints_for_object( + const PrintObject &object, + const std::vector> ®ions_by_extruder, + const std::vector &physical_extruders, + double z_min, + double z_max, + coord_t clearance = 0); + } // namespace Slic3r diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 50a6235f77..fbdef80299 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -5201,13 +5201,25 @@ std::string GCode::generate_object_skirt_group(const Print &print, object_skirt_tools, layer, extruder_id, m_skirt_group_done[group_idx]); } -std::string GCode::generate_object_brim(const Print &print, const PrintObject &object, size_t instance_id, bool first_layer) +std::string GCode::generate_object_brim( + const Print &print, + const PrintObject &object, + const size_t instance_id, + const bool first_layer, + const unsigned int extruder_id) { if (!first_layer) return {}; - auto emit_brim = [this](const ExtrusionEntityCollection& brim, const std::vector& instances) { + auto emit_brim = [this, extruder_id](const ExtrusionEntityCollection& brim, + const std::vector& instances, + const unsigned int brim_filament_id) { std::string gcode; + // Combined brims have an explicit owner filament. Waiting for that + // filament avoids inheriting whichever tool first encounters a carrier + // object in the layer traversal. + if (brim_filament_id != extruder_id) + return gcode; const bool already_emitted = std::none_of(instances.begin(), instances.end(), [this](const ObjectInstanceID& instance) { return m_objsWithBrim.find(instance) != m_objsWithBrim.end(); }); @@ -5232,7 +5244,7 @@ std::string GCode::generate_object_brim(const Print &print, const PrintObject &o std::string gcode; for (const Print::SkirtBrimGroup::Brim& brim : print.skirt_brim_groups()[group_idx].brims) if (std::find(brim.instances.begin(), brim.instances.end(), object_instance_id) != brim.instances.end()) - gcode += emit_brim(brim.brim, brim.instances); + gcode += emit_brim(brim.brim, brim.instances, brim.filament_id); return gcode; } @@ -6497,7 +6509,8 @@ LayerResult GCode::process_layer( const LayerToPrint &layer_to_print = layers[instance_to_print.layer_id]; if (visit.first_visit && print_wipe_extrusions == (is_anything_overridden ? 1 : 0)) { gcode += generate_object_skirt_group(print, instance_to_print.print_object, instance_to_print.instance_id, layer_tools, layer, extruder_id); - gcode += generate_object_brim(print, instance_to_print.print_object, instance_to_print.instance_id, first_layer); + gcode += generate_object_brim( + print, instance_to_print.print_object, instance_to_print.instance_id, first_layer, extruder_id); } // To control print speed of the 1st object layer printed over raft interface. diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 561c8b77c9..630ab242e8 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -370,7 +370,8 @@ private: std::string generate_object_brim(const Print &print, const PrintObject &object, size_t instance_id, - bool first_layer); + bool first_layer, + unsigned int extruder_id); LayerResult process_layer( const Print &print, diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 42021d3090..cb6b28eebc 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -9,6 +9,7 @@ #include "BoundingBox.hpp" #include "Brim.hpp" #include "ClipperUtils.hpp" +#include "ExclusionVolumeGeometry.hpp" #include "Extruder.hpp" #include "FilamentMixer.hpp" #include "Flow.hpp" @@ -2906,7 +2907,11 @@ void Print::process(long long *time_cost_with_cache, bool use_cache) // Orca: Build both the old object-keyed brim map and the per-instance // maps used by skirt/brim groups. m_brimMap.clear(); + m_brimFilamentMap.clear(); m_brimMapByInstance.clear(); + for (const auto& [object_id, filament] : objPrintVec) + if (filament > 0) + m_brimFilamentMap.emplace(object_id, filament - 1); m_first_layer_convex_hull.points.clear(); if (this->has_brim()) { Polygons islands_area; @@ -3287,7 +3292,17 @@ void Print::_make_skirt() } } - auto make_brims_for_skirt_brim_group = [this](const std::vector& group_instances) { + const std::vector> brim_exclusion_regions = + translated_bed_exclusion_volumes_by_extruder(*this); + const bool has_brim_exclusions = std::any_of( + brim_exclusion_regions.begin(), brim_exclusion_regions.end(), + [](const std::vector ®ions) { return !regions.empty(); }); + const bool has_nozzle_specific_brim_exclusions = has_brim_exclusions && + m_config.bed_exclude_area_mode.value != BedExcludeAreaMode::Shared; + + auto make_brims_for_skirt_brim_group = + [this, &brim_exclusion_regions, has_nozzle_specific_brim_exclusions] + (const std::vector& group_instances) { std::vector brims; std::vector brim_instances; for (const ObjectInstanceID& instance : group_instances) { @@ -3296,10 +3311,31 @@ void Print::_make_skirt() brim_instances.push_back(instance); } + auto brim_filament = [this](const ObjectInstanceID& instance) -> std::optional { + const auto it = m_brimFilamentMap.find(instance.object_id); + return it == m_brimFilamentMap.end() ? std::nullopt : + std::optional(it->second); + }; + auto compatible_brim_nozzles = + [this, &brim_filament, &brim_exclusion_regions, has_nozzle_specific_brim_exclusions] + (const ObjectInstanceID& first, const ObjectInstanceID& second) { + if (!has_nozzle_specific_brim_exclusions) + return true; + const std::optional first_filament = brim_filament(first); + const std::optional second_filament = brim_filament(second); + return first_filament.has_value() && second_filament.has_value() && + bed_exclusion_physical_extruders( + *this, { *first_filament, *second_filament }, + brim_exclusion_regions.size(), 0).size() == 1; + }; + const bool combine_group_brims = m_config.combine_brims && brim_instances.size() > 1; if (!combine_group_brims) { - for (const ObjectInstanceID& instance : brim_instances) - brims.push_back({ m_brimMapByInstance.at(instance), { instance } }); + for (const ObjectInstanceID& instance : brim_instances) { + const std::optional filament = brim_filament(instance); + if (filament.has_value()) + brims.push_back({ m_brimMapByInstance.at(instance), { instance }, *filament }); + } return brims; } @@ -3327,6 +3363,7 @@ void Print::_make_skirt() for (size_t j = i + 1; j < brim_instances.size(); ++j) { const auto area_j = m_objectBrimAreasByInstance.find(brim_instances[j]); if (area_j != m_objectBrimAreasByInstance.end() && + compatible_brim_nozzles(brim_instances[i], brim_instances[j]) && !intersection_ex(offset_ex(area_i->second, brim_contact_distance, jtRound, SCALED_RESOLUTION), area_j->second).empty()) unite_brims(i, j); } @@ -3337,9 +3374,12 @@ void Print::_make_skirt() combined_brim_ids[find_brim_parent(i)].push_back(brim_instances[i]); for (const auto& [_, instances] : combined_brim_ids) { + const std::optional filament = brim_filament(instances.front()); + if (!filament.has_value()) + continue; if (instances.size() == 1) { const ObjectInstanceID& instance = instances.front(); - brims.push_back({ m_brimMapByInstance.at(instance), { instance } }); + brims.push_back({ m_brimMapByInstance.at(instance), { instance }, *filament }); continue; } @@ -3351,8 +3391,26 @@ void Print::_make_skirt() const float brim_cleanup_delta = std::max(scaled_resolution, float(SCALED_EPSILON)); combined_area = offset2_ex(combined_area, brim_cleanup_delta, -brim_cleanup_delta, jtRound, scaled_resolution); + // The group has one known physical nozzle. Clip after union and + // cleanup so the geometry consumed by path generation remains + // valid for the exact filament recorded on the combined brim. + const std::vector physical_extruders = bed_exclusion_physical_extruders( + *this, { *filament }, brim_exclusion_regions.size(), 0); + const coord_t width_spacing_delta = std::max( + 0, brim_flow().scaled_width() - brim_flow().scaled_spacing()); + const coord_t exclusion_clearance = + (width_spacing_delta + 1) / 2 + coord_t(SCALED_EPSILON); + const ExPolygons exclusions = active_bed_exclusion_footprints( + brim_exclusion_regions, physical_extruders, 0.0, + std::max(0.0, skirt_first_layer_height()), Point(0, 0), exclusion_clearance); + if (!exclusions.empty()) + combined_area = diff_ex(combined_area, exclusions); + if (combined_area.empty()) + continue; + Polygons islands_area; - brims.push_back({ makeBrimInfillFromPlateCoordinates(combined_area, *this, islands_area), instances }); + brims.push_back({ makeBrimInfillFromPlateCoordinates(combined_area, *this, islands_area), + instances, *filament }); } return brims; diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 4d01e64580..03489470a4 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -1009,6 +1009,8 @@ public: struct Brim { ExtrusionEntityCollection brim; std::vector instances; + // Zero-based logical filament selected when the brim was planned. + unsigned int filament_id { unsigned(-1) }; }; ExtrusionEntityCollection skirt; @@ -1321,6 +1323,8 @@ private: bool m_has_shared_per_object_skirt { false }; // Orca: Object-keyed brim paths kept for existing code. std::map m_brimMap; + // Zero-based logical filament selected for each object's brim. + std::map m_brimFilamentMap; // Orca: Actual brim paths keyed by object instance. std::map m_brimMapByInstance; // Orca: Translated brim areas keyed by instance, used to find touching brims. diff --git a/src/libslic3r/Support/SupportCommon.cpp b/src/libslic3r/Support/SupportCommon.cpp index e734608803..9560d02fab 100644 --- a/src/libslic3r/Support/SupportCommon.cpp +++ b/src/libslic3r/Support/SupportCommon.cpp @@ -1,4 +1,5 @@ #include "../ClipperUtils.hpp" +#include "../ExclusionVolumeGeometry.hpp" // #include "../ClipperZUtils.hpp" #include "../ExtrusionEntityCollection.hpp" #include "../Layer.hpp" @@ -35,6 +36,124 @@ namespace Slic3r { +namespace { + +int object_layer_id_at_z(const PrintObject &object, const coordf_t print_z) +{ + const ConstLayerPtrsAdaptor layers = object.layers(); + if (layers.empty()) + return -1; + const auto it = std::lower_bound(layers.begin(), layers.end(), print_z - EPSILON, + [](const Layer *layer, const coordf_t z) { return layer->print_z < z; }); + return int(it == layers.end() ? layers.size() - 1 : size_t(it - layers.begin())); +} + +bool support_layer_uses_interface_material(const SupportGeneratorLayer &layer) +{ + return one_of(layer.layer_type, { + SupporLayerType::RaftInterface, + SupporLayerType::BottomContact, + SupporLayerType::BottomInterface, + SupporLayerType::TopContact, + SupporLayerType::TopInterface }); +} + +void trim_polygons(Polygons &polygons, const Polygons &excluded) +{ + if (!polygons.empty() && !excluded.empty()) + polygons = diff(polygons, excluded, ApplySafetyOffset::Yes); +} + +} // namespace + +std::vector support_exclusion_filaments( + const PrintObject &object, + const bool interface_material) +{ + const int configured = interface_material ? object.config().support_interface_filament.value : + object.config().support_filament.value; + if (configured > 0) + return { unsigned(configured - 1) }; + + // "Current filament" is assigned during tool ordering, not from the + // supported object. It may therefore use a filament from another object, + // or one selected for flush-into-support, on any particular layer. + return object.print() == nullptr ? object.object_extruders() : object.print()->extruders(false); +} + +std::vector support_exclusion_areas_for_layers( + const PrintObject &object, + const std::vector> &layer_z_ranges, + const bool interface_material) +{ + std::vector result(layer_z_ranges.size()); + if (layer_z_ranges.empty() || object.print() == nullptr) + return result; + + const Print &print = *object.print(); + const std::vector> regions_by_extruder = + get_bed_excluded_regions_by_extruder(print.config()); + if (regions_by_extruder.empty() || + std::all_of(regions_by_extruder.begin(), regions_by_extruder.end(), + [](const std::vector ®ions) { return regions.empty(); })) + return result; + + const std::vector filaments = support_exclusion_filaments(object, interface_material); + for (size_t idx = 0; idx < layer_z_ranges.size(); ++idx) { + const auto [z_min, z_max] = layer_z_ranges[idx]; + const int layer_id = object_layer_id_at_z(object, z_max); + const std::vector physical_extruders = bed_exclusion_physical_extruders( + print, filaments, regions_by_extruder.size(), layer_id); + result[idx] = to_polygons(active_bed_exclusion_footprints_for_object( + object, regions_by_extruder, physical_extruders, z_min, z_max, coord_t(SCALED_EPSILON))); + } + return result; +} + +void trim_support_layers_by_exclusion_volumes( + const PrintObject &object, + const SupportGeneratorLayersPtr &raft_layers, + const SupportGeneratorLayersPtr &bottom_contacts, + const SupportGeneratorLayersPtr &top_contacts, + const SupportGeneratorLayersPtr &intermediate_layers, + const SupportGeneratorLayersPtr &interface_layers, + const SupportGeneratorLayersPtr &base_interface_layers) +{ + SupportGeneratorLayersPtr layers; + layers.reserve(raft_layers.size() + bottom_contacts.size() + top_contacts.size() + + intermediate_layers.size() + interface_layers.size() + base_interface_layers.size()); + for (const SupportGeneratorLayersPtr *source : { + &raft_layers, &bottom_contacts, &top_contacts, &intermediate_layers, + &interface_layers, &base_interface_layers }) + append(layers, *source); + std::sort(layers.begin(), layers.end()); + layers.erase(std::unique(layers.begin(), layers.end()), layers.end()); + + for (const bool interface_material : { false, true }) { + SupportGeneratorLayersPtr selected; + std::vector> z_ranges; + for (SupportGeneratorLayer *layer : layers) { + if (layer != nullptr && support_layer_uses_interface_material(*layer) == interface_material) { + selected.emplace_back(layer); + z_ranges.emplace_back(layer->bottom_print_z(), layer->print_z); + } + } + + const std::vector excluded = + support_exclusion_areas_for_layers(object, z_ranges, interface_material); + for (size_t idx = 0; idx < selected.size(); ++idx) { + SupportGeneratorLayer &layer = *selected[idx]; + trim_polygons(layer.polygons, excluded[idx]); + if (layer.contact_polygons) + trim_polygons(*layer.contact_polygons, excluded[idx]); + if (layer.overhang_polygons) + trim_polygons(*layer.overhang_polygons, excluded[idx]); + if (layer.enforcer_polygons) + trim_polygons(*layer.enforcer_polygons, excluded[idx]); + } + } +} + // how much we extend support around the actual contact area //FIXME this should be dependent on the nozzle diameter! #define SUPPORT_MATERIAL_MARGIN 1.5 diff --git a/src/libslic3r/Support/SupportCommon.hpp b/src/libslic3r/Support/SupportCommon.hpp index 531daaa0a8..11f336ccd4 100644 --- a/src/libslic3r/Support/SupportCommon.hpp +++ b/src/libslic3r/Support/SupportCommon.hpp @@ -46,6 +46,32 @@ void tree_supports_generate_paths(ExtrusionEntitiesPtr &dst, const Polygons &pol void fill_expolygons_with_sheath_generate_paths( ExtrusionEntitiesPtr &dst, const Polygons &polygons, Fill *filler, float density, ExtrusionRole role, const Flow &flow, const SupportParameters& support_params, bool with_sheath, bool no_sort); +// Return every logical filament which may be selected for this support role. +// An explicit assignment has one result; "current filament" is intentionally +// print-wide because Orca resolves it later while ordering tools and wiping. +std::vector support_exclusion_filaments( + const PrintObject &object, + bool interface_material); + +// Build conservative, object-local exclusion masks for generated support. +// `interface_material` selects the support-interface filament; false selects +// the base support filament. Each pair describes the actual extrusion slab. +std::vector support_exclusion_areas_for_layers( + const PrintObject &object, + const std::vector> &layer_z_ranges, + bool interface_material); + +// Remove exclusion volumes from every support and raft polygon category before +// SupportLayer installation and toolpath generation. +void trim_support_layers_by_exclusion_volumes( + const PrintObject &object, + const SupportGeneratorLayersPtr &raft_layers, + const SupportGeneratorLayersPtr &bottom_contacts, + const SupportGeneratorLayersPtr &top_contacts, + const SupportGeneratorLayersPtr &intermediate_layers, + const SupportGeneratorLayersPtr &interface_layers, + const SupportGeneratorLayersPtr &base_interface_layers); + // returns sorted layers SupportGeneratorLayersPtr generate_support_layers( PrintObject &object, diff --git a/src/libslic3r/Support/SupportMaterial.cpp b/src/libslic3r/Support/SupportMaterial.cpp index a955eb5ca7..1aa7a2fe25 100644 --- a/src/libslic3r/Support/SupportMaterial.cpp +++ b/src/libslic3r/Support/SupportMaterial.cpp @@ -509,6 +509,10 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) BOOST_LOG_TRIVIAL(info) << "Support generator - Creating layers"; + trim_support_layers_by_exclusion_volumes( + object, raft_layers, bottom_contacts, top_contacts, intermediate_layers, + interface_layers, base_interface_layers); + // For debugging purposes, one may want to show only some of the support extrusions. // raft_layers.clear(); // bottom_contacts.clear(); diff --git a/src/libslic3r/Support/TreeModelVolumes.cpp b/src/libslic3r/Support/TreeModelVolumes.cpp index 70c33aab0d..568d9ec191 100644 --- a/src/libslic3r/Support/TreeModelVolumes.cpp +++ b/src/libslic3r/Support/TreeModelVolumes.cpp @@ -136,22 +136,18 @@ TreeModelVolumes::TreeModelVolumes( } }); } - if (! additional_excluded_areas.empty()) { - tbb::parallel_for(tbb::blocked_range(0, m_anti_overhang.size()), - [&](const tbb::blocked_range &range) { - for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) { - if (layer_idx < coord_t(additional_excluded_areas.size())) - append(m_anti_overhang[layer_idx], additional_excluded_areas[layer_idx]); - // if (SUPPORT_TREE_AVOID_SUPPORT_BLOCKER) - // append(m_anti_overhang[layer_idx], storage.support.supportLayers[layer_idx].anti_overhang); - //FIXME block wipe tower - // if (storage.primeTower.enabled) - // append(m_anti_overhang[layer_idx], layer_idx == 0 ? storage.primeTower.outer_poly_first_layer : storage.primeTower.outer_poly); - m_anti_overhang[layer_idx] = union_(m_anti_overhang[layer_idx]); - } - }); - } #endif + + if (!additional_excluded_areas.empty()) { + m_anti_overhang.resize(std::max(m_anti_overhang.size(), additional_excluded_areas.size())); + tbb::parallel_for(tbb::blocked_range(0, additional_excluded_areas.size()), + [&](const tbb::blocked_range &range) { + for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++layer_idx) { + append(m_anti_overhang[layer_idx], additional_excluded_areas[layer_idx]); + m_anti_overhang[layer_idx] = union_(m_anti_overhang[layer_idx]); + } + }); + } } void TreeModelVolumes::precalculate(const PrintObject& print_object, const coord_t max_layer, std::function throw_on_cancel) @@ -432,7 +428,8 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex if (calculate_placable) data_placeable.allocate(data.begin(), data.end()); - for (size_t outline_idx : layer_outline_indices) + for (size_t outline_pos = 0; outline_pos < layer_outline_indices.size(); ++outline_pos) { + const size_t outline_idx = layer_outline_indices[outline_pos]; if (const std::vector &outlines = m_layer_outlines[outline_idx].second; ! outlines.empty()) { const TreeSupportMeshGroupSettings &settings = m_layer_outlines[outline_idx].first; const coord_t layer_height = settings.layer_height; @@ -469,7 +466,7 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex }); // 2) Sum over top / bottom ranges. - const bool processing_last_mesh = outline_idx == layer_outline_indices.back(); + const bool processing_last_mesh = outline_pos + 1 == layer_outline_indices.size(); tbb::parallel_for(tbb::blocked_range(data.begin(), data.end()), [&collision_areas_offsetted, &outlines, &machine_border = m_machine_border, &anti_overhang = m_anti_overhang, radius, xy_distance, z_distance_bottom_layers, z_distance_top_layers, min_resolution = m_min_resolution, &data, processing_last_mesh, &throw_on_cancel] @@ -563,6 +560,7 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex // Calculating just the collision areas. } } + } #ifdef SLIC3R_TREESUPPORTS_PROGRESS { std::lock_guard critical_section(*m_critical_progress); diff --git a/src/libslic3r/Support/TreeSupport3D.cpp b/src/libslic3r/Support/TreeSupport3D.cpp index 3cd3f4110d..a1d95ad90f 100644 --- a/src/libslic3r/Support/TreeSupport3D.cpp +++ b/src/libslic3r/Support/TreeSupport3D.cpp @@ -3438,12 +3438,41 @@ static void generate_support_areas(Print &print, TreeSupport* tree_support, cons m_progress_offset = counter == 0 ? 0 : TREE_PROGRESS_TOTAL * (double(counter) * m_progress_multiplier); #endif // SLIC3R_TREESUPPORT_PROGRESS PrintObject &print_object = *print.get_object(processing.second.front()); + const size_t num_raft_layers_for_exclusions = config.raft_layers.size(); + std::vector> tree_layer_z_ranges; + tree_layer_z_ranges.reserve(num_raft_layers_for_exclusions + print_object.layer_count()); + coordf_t previous_z = 0.; + for (const coordf_t print_z : config.raft_layers) { + tree_layer_z_ranges.emplace_back(previous_z, print_z); + previous_z = print_z; + } + for (const Layer *layer : print_object.layers()) { + tree_layer_z_ranges.emplace_back(layer->print_z - layer->height, layer->print_z); + } + // A tree is one continuous structure while "current filament" may + // alternate between base and interface nozzles from layer to layer. + // Planning against both masks prevents a locally valid layer from + // forcing a branch through another possible nozzle's exclusion volume. + std::vector exclusion_areas = + support_exclusion_areas_for_layers(print_object, tree_layer_z_ranges, false); + const bool tree_uses_interface_material = !config.raft_layers.empty() || + print_object.config().support_interface_top_layers.value > 0 || + number_of_support_interface_bottom_layers(print_object.config()) > 0; + if (tree_uses_interface_material) { + const std::vector interface_exclusion_areas = + support_exclusion_areas_for_layers(print_object, tree_layer_z_ranges, true); + for (size_t layer_idx = 0; layer_idx < exclusion_areas.size(); ++layer_idx) { + append(exclusion_areas[layer_idx], interface_exclusion_areas[layer_idx]); + exclusion_areas[layer_idx] = union_(exclusion_areas[layer_idx]); + } + } + // Generator for model collision, avoidance and internal guide volumes. TreeModelVolumes volumes{ print_object, build_volume, config.maximum_move_distance, config.maximum_move_distance_slow, processing.second.front(), #ifdef SLIC3R_TREESUPPORTS_PROGRESS m_progress_multiplier, m_progress_offset, #endif // SLIC3R_TREESUPPORTS_PROGRESS - /* additional_excluded_areas */{} }; + exclusion_areas }; //FIXME generating overhangs just for the first mesh of the group. assert(processing.second.size() == 1); @@ -3591,6 +3620,9 @@ static void generate_support_areas(Print &print, TreeSupport* tree_support, cons // Produce the support G-code. SupportGeneratorLayersPtr raft_layers = generate_raft_base(print_object, support_params, print_object.slicing_parameters(), top_contacts, interface_layers, base_interface_layers, intermediate_layers, layer_storage); + trim_support_layers_by_exclusion_volumes( + print_object, raft_layers, bottom_contacts, top_contacts, intermediate_layers, + interface_layers, base_interface_layers); SupportGeneratorLayersPtr layers_sorted = generate_support_layers(print_object, raft_layers, bottom_contacts, top_contacts, intermediate_layers, interface_layers, base_interface_layers); // BBS: This is a hack to avoid the support being generated outside the bed area. See #4769.