Preserve top support interfaces with synchronized layer gaps (#13939)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rodrigo Faselli <162915171+RF47@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-09 18:20:07 -03:00
1 parent 868686b307
commit 320f1bb7fc
2 files changed
+178 -2

No files matched your search

+10 -1
View File
@@ -3385,7 +3385,16 @@ void PrintObjectSupportMaterial::trim_support_layers_by_object(
break;
bool is_overlap = is_layers_overlap(support_layer, object_layer);
for (const ExPolygon& expoly : object_layer.lslices) {
// Only relax trimming across the gap to the overhang assigned to this top contact.
const ExPolygons *trim_source = &object_layer.lslices;
ExPolygons trim_continuous;
if (support_layer.layer_type == SupporLayerType::TopContact && i > 0 &&
i >= support_layer.idx_object_layer_above &&
object_layer.bottom_z() > support_layer.print_z + EPSILON) {
trim_continuous = intersection_ex(object_layer.lslices, object.layers()[i - 1]->lslices);
trim_source = &trim_continuous;
}
for (const ExPolygon& expoly : *trim_source) {
// BBS
bool is_sharptail = !intersection_ex({ expoly }, object_layer.sharp_tails).empty();
coordf_t trimming_offset = is_sharptail ? scale_(sharp_tail_xy_gap) :
+168 -1
View File
@@ -7,11 +7,13 @@
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <catch2/generators/catch_generators.hpp>
#include "libslic3r/GCodeReader.hpp"
#include "libslic3r/BoundingBox.hpp"
#include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/ExPolygon.hpp"
#include "libslic3r/ExtrusionEntity.hpp"
#include "libslic3r/ExtrusionEntityCollection.hpp"
#include "libslic3r/Point.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/Layer.hpp"
#include <cmath>
@@ -124,6 +126,171 @@ static TriangleMesh support_capital()
return model;
}
TEST_CASE("Top support interfaces cover an overhang with a synchronized variable layer gap", "[SupportMaterial][Regression]")
{
const bool independent = GENERATE(false, true);
const bool variable = GENERATE(false, true);
const double top_gap = GENERATE(0.0, 0.2);
CAPTURE(independent, variable, top_gap);
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({
{ "enable_support", 1 },
{ "support_type", "normal(auto)" },
{ "layer_height", 0.2 },
{ "initial_layer_print_height", 0.2 },
{ "independent_support_layer_height", independent },
{ "support_on_build_plate_only", 0 },
{ "support_top_z_distance", top_gap },
{ "support_bottom_z_distance", 0.2 },
{ "support_object_xy_distance", 0.35 },
{ "support_interface_spacing", 0.0 },
{ "support_interface_top_layers", 2 },
{ "support_interface_bottom_layers", 0 },
{ "gcode_comments", true },
});
Print print;
Model model;
init_print({ support_capital() }, print, model, config);
if (variable) {
// Below the overhang at Z=12, 0.16 mm layers round the nominal 0.2 mm
// synchronized gap down. No material painting is involved.
model.objects.front()->layer_height_profile.set(std::vector<coordf_t>{
0.0, 0.2, 1.6, 0.2, 1.6, 0.16, 14.0, 0.16,
});
print.apply(model, config);
}
print.process();
const PrintObject &object = *print.objects().front();
REQUIRE(!object.support_layers().empty());
const SupportLayer &contact = *object.support_layers().back();
REQUIRE(contact.print_z <= 12.0 + EPSILON);
REQUIRE(contact.print_z > 11.5);
Polygons coverage;
Polygons footprint;
const ExtrusionEntityCollection fills = contact.support_fills.flatten();
for (const ExtrusionEntity *entity : fills.entities)
if (entity->role() == erSupportMaterialInterface) {
entity->polygons_covered_by_spacing(coverage, 0.f);
entity->polygons_covered_by_width(footprint, 0.f);
}
const auto &layers = object.layers();
const auto wall_layer = std::find_if(layers.begin(), layers.end(), [&contact](const Layer *layer) {
return layer->bottom_z() < contact.print_z - EPSILON && layer->print_z >= contact.print_z - EPSILON;
});
REQUIRE(wall_layer != layers.end());
REQUIRE(intersection(footprint, to_polygons((*wall_layer)->lslices)).empty());
if (top_gap > 0.0) {
const auto next_layer = std::find_if(layers.begin(), layers.end(), [&contact](const Layer *layer) {
return layer->bottom_z() >= contact.print_z - EPSILON;
});
REQUIRE(next_layer != layers.end());
REQUIRE(intersection(footprint, to_polygons((*next_layer)->lslices)).empty());
}
// Check interior areas on both sides of the stem, away from the XY gap.
const BoundingBox bounds = get_extents(object.layers().back()->lslices);
const Point center = bounds.center();
for (double x : {-10.0, 10.0}) {
const Point lower = center + Point::new_scale(x - 2.0, -2.0);
const Point upper = center + Point::new_scale(x + 2.0, 2.0);
const Polygon target({lower, Point(upper.x(), lower.y()), upper, Point(lower.x(), upper.y())});
CAPTURE(x, contact.print_z);
REQUIRE(area(intersection(Polygons{target}, coverage)) > 0.9 * target.area());
}
}
TEST_CASE("Top support interfaces keep clearance below expanding overhang walls", "[SupportMaterial][Regression]")
{
const bool independent = GENERATE(false, true);
const bool variable = GENERATE(false, true);
const double top_gap = 0.2;
const double object_height = variable ? 0.16 : 0.2;
const double effective_gap = independent ? top_gap : std::round(top_gap / object_height) * object_height;
TriangleMesh mesh = make_cube(40, 40, 2);
TriangleMesh overhang = make_pyramid(30, 6);
overhang.rotate_x(float(M_PI));
overhang.translate(20, 20, 7);
mesh.merge(overhang);
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({
{ "enable_support", 1 },
{ "support_type", "normal(auto)" },
{ "layer_height", 0.2 },
{ "initial_layer_print_height", 0.2 },
{ "independent_support_layer_height", independent },
{ "support_on_build_plate_only", 0 },
{ "support_top_z_distance", top_gap },
{ "support_bottom_z_distance", 0.2 },
{ "support_object_xy_distance", 0.35 },
{ "support_interface_top_layers", 2 },
{ "support_interface_bottom_layers", 0 },
{ "thick_bridges", false },
});
Print print;
Model model;
init_print({ mesh }, print, model, config);
if (variable) {
model.objects.front()->layer_height_profile.set(std::vector<coordf_t>{
0.0, 0.2, 1.6, 0.2, 1.6, object_height, 7.0, object_height,
});
print.apply(model, config);
}
print.process();
const PrintObject &object = *print.objects().front();
size_t checked_layers = 0;
for (const SupportLayer *support : object.support_layers()) {
if (support->print_z <= 3.0 || support->print_z >= 6.5)
continue;
Polygons footprint;
const ExtrusionEntityCollection fills = support->support_fills.flatten();
for (const ExtrusionEntity *entity : fills.entities)
if (entity->role() == erSupportMaterialInterface)
entity->polygons_covered_by_width(footprint, 0.f);
if (footprint.empty())
continue;
for (const Layer *layer : object.layers()) {
if (layer->bottom_z() >= support->print_z - EPSILON &&
layer->bottom_z() < support->print_z + effective_gap - EPSILON) {
++checked_layers;
CAPTURE(independent, variable, support->print_z, layer->bottom_z(), effective_gap);
REQUIRE(intersection(footprint, to_polygons(layer->lslices)).empty());
}
}
}
REQUIRE(checked_layers > 0);
}
TEST_CASE("Top support interfaces keep clearance when clamped to the first layer", "[SupportMaterial][Regression]")
{
TriangleMesh mesh = make_pyramid(30, 6);
mesh.rotate_x(float(M_PI));
mesh.translate(15, 15, 6);
Print print;
init_and_process_print({ mesh }, print, {
{ "enable_support", 1 },
{ "support_type", "normal(auto)" },
{ "layer_height", 0.28 },
{ "initial_layer_print_height", 0.2 },
{ "independent_support_layer_height", false },
{ "support_top_z_distance", 0.2 },
{ "support_object_xy_distance", 0.35 },
{ "support_interface_top_layers", 2 },
{ "support_interface_bottom_layers", 0 },
{ "thick_bridges", false },
});
const PrintObject &object = *print.objects().front();
REQUIRE(!object.support_layers().empty());
const SupportLayer &first = *object.support_layers().front();
REQUIRE_THAT(first.print_z, Catch::Matchers::WithinAbs(0.2, EPSILON));
REQUIRE(object.layers().size() > 1);
Polygons footprint;
const ExtrusionEntityCollection fills = first.support_fills.flatten();
for (const ExtrusionEntity *entity : fills.entities)
if (entity->role() == erSupportMaterialInterface)
entity->polygons_covered_by_width(footprint, 0.f);
REQUIRE(intersection(footprint, to_polygons(object.layers()[1]->lslices)).empty());
}
TEST_CASE("Three raft layers are created", "[SupportMaterial]")
{
Slic3r::Print print;