mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-29 16:36:01 -05:00
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
187 lines
6.1 KiB
C++
187 lines
6.1 KiB
C++
#include "ExclusionVolumeGeometry.hpp"
|
|
#include "ExPolygon.hpp"
|
|
#include "FilamentMixer.hpp"
|
|
#include "Point.hpp"
|
|
#include "Polygon.hpp"
|
|
#include "PrintConfig.hpp"
|
|
#include "libslic3r.h"
|
|
#include <cmath>
|
|
#include <cstddef>
|
|
#include <vector>
|
|
|
|
#include "BoundingBox.hpp"
|
|
#include "ClipperUtils.hpp"
|
|
#include "Geometry/ConvexHull.hpp"
|
|
#include "Print.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <numeric>
|
|
#include <utility>
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace {
|
|
|
|
constexpr double Z_EPSILON_MM = 1e-6;
|
|
|
|
void append_active_footprints(
|
|
Polygons &out,
|
|
const std::vector<BedExcludeRegion> ®ions,
|
|
const double z_min,
|
|
const double z_max,
|
|
const Point &translation)
|
|
{
|
|
for (const BedExcludeRegion ®ion : regions) {
|
|
if (region.polygon.points.size() < 3 || region.z_max < region.z_min ||
|
|
!bed_exclusion_z_ranges_overlap(z_min, z_max, region.z_min, region.z_max))
|
|
continue;
|
|
|
|
Polygon footprint = region.polygon;
|
|
footprint.translate(translation);
|
|
out.emplace_back(std::move(footprint));
|
|
}
|
|
}
|
|
|
|
ExPolygons union_active_footprints(Polygons footprints, const coord_t clearance)
|
|
{
|
|
if (footprints.empty())
|
|
return {};
|
|
|
|
ExPolygons result = union_ex(footprints);
|
|
if (clearance > 0)
|
|
result = offset_ex(result, float(clearance));
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
bool bed_exclusion_z_ranges_overlap(
|
|
double first_min,
|
|
double first_max,
|
|
double second_min,
|
|
double second_max)
|
|
{
|
|
if (first_min > first_max)
|
|
std::swap(first_min, first_max);
|
|
if (second_min > second_max)
|
|
std::swap(second_min, second_max);
|
|
return first_max >= second_min - Z_EPSILON_MM && first_min <= second_max + Z_EPSILON_MM;
|
|
}
|
|
|
|
Polygon bed_exclusion_arrange_polygon(const Polygon &polygon)
|
|
{
|
|
if (polygon.points.size() < 3)
|
|
return polygon;
|
|
|
|
const Polygon convex_hull = Geometry::convex_hull(polygon.points);
|
|
const double polygon_area = std::abs(polygon.area());
|
|
const double hull_area = std::abs(convex_hull.area());
|
|
const double tolerance = std::max(1.0, hull_area) * 1e-12;
|
|
if (std::abs(hull_area - polygon_area) <= tolerance)
|
|
return polygon;
|
|
|
|
return get_extents(polygon).polygon();
|
|
}
|
|
|
|
ExPolygons active_bed_exclusion_footprints(
|
|
const std::vector<BedExcludeRegion> ®ions,
|
|
const double z_min,
|
|
const double z_max,
|
|
const Point &translation,
|
|
const coord_t clearance)
|
|
{
|
|
Polygons footprints;
|
|
footprints.reserve(regions.size());
|
|
append_active_footprints(footprints, regions, z_min, z_max, translation);
|
|
return union_active_footprints(std::move(footprints), clearance);
|
|
}
|
|
|
|
ExPolygons active_bed_exclusion_footprints(
|
|
const std::vector<std::vector<BedExcludeRegion>> ®ions_by_extruder,
|
|
const std::vector<size_t> &physical_extruders,
|
|
const double z_min,
|
|
const double z_max,
|
|
const Point &translation,
|
|
const coord_t clearance)
|
|
{
|
|
Polygons footprints;
|
|
std::vector<bool> visited(regions_by_extruder.size(), false);
|
|
for (const size_t extruder_id : physical_extruders) {
|
|
if (extruder_id >= regions_by_extruder.size() || visited[extruder_id])
|
|
continue;
|
|
visited[extruder_id] = true;
|
|
const std::vector<BedExcludeRegion> ®ions = regions_by_extruder[extruder_id];
|
|
footprints.reserve(footprints.size() + regions.size());
|
|
append_active_footprints(footprints, regions, z_min, z_max, translation);
|
|
}
|
|
return union_active_footprints(std::move(footprints), clearance);
|
|
}
|
|
|
|
std::vector<size_t> bed_exclusion_physical_extruders(
|
|
const Print &print,
|
|
const std::vector<unsigned int> &filament_ids,
|
|
const size_t physical_extruder_count,
|
|
const int layer_id)
|
|
{
|
|
if (physical_extruder_count == 0)
|
|
return {};
|
|
|
|
std::vector<size_t> 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;
|
|
// 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 : 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 &&
|
|
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<std::vector<BedExcludeRegion>> ®ions_by_extruder,
|
|
const std::vector<size_t> &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
|