From 3afdf05e3edbda1001ab7841b901087766a75487 Mon Sep 17 00:00:00 2001 From: wintergua Date: Tue, 19 Sep 2023 14:58:01 +0800 Subject: [PATCH] FIX: the brim generated from inner island should be limited Inner island is the one which inside a hole of the object. the brim area of such island should be limited by the hole JIRA-ID: https://jira.bambooolab.com/browse/STUDIO-4521 Change-Id: Iae70dbefc87b0cb7dcb19578f29aad16e9bd630d (cherry picked from commit 2bf63f0ece88a230a37f83d156a44bdc76a0d094) --- src/libslic3r/Brim.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp index 372d50255..f20856791 100644 --- a/src/libslic3r/Brim.cpp +++ b/src/libslic3r/Brim.cpp @@ -826,6 +826,19 @@ static ExPolygons outer_inner_brim_area(const Print& print, auto bedPoly = Model::getBedPolygon(); auto bedExPoly = diff_ex((offset(bedPoly, scale_(30.), jtRound, SCALED_RESOLUTION)), { bedPoly }); + auto save_polygon_if_is_inner_island = [](const Polygons& holes_area, const Polygon& contour, int& hole_index) { + for (size_t i = 0; i < holes_area.size(); i++) { + Polygons contour_polys; + contour_polys.push_back(contour); + if (diff_ex(contour_polys, { holes_area[i] }).empty()) { + // BBS: this is an inner island inside holes_area[i], save + hole_index = i; + return; + } + } + hole_index = -1; + }; + for (unsigned int extruderNo : printExtruders) { ++extruderNo; for (const auto& objectWithExtruder : objPrintVec) { @@ -849,6 +862,12 @@ static ExPolygons outer_inner_brim_area(const Print& print, double deltaT = getTemperatureFromExtruder(object); double adhension = getadhesionCoeff(object); double maxSpeed = Model::findMaxSpeed(object->model_object()); + + //BBS: collect holes area which is used to limit the brim of inner island + Polygons holes_area; + for (const ExPolygon& ex_poly : object->layers().front()->lslices) + polygons_append(holes_area, ex_poly.holes); + // BBS: brims are generated by volume groups for (const auto& volumeGroup : object->firstLayerObjGroups()) { // if this object has raft only update no_brim_area_object @@ -876,6 +895,7 @@ static ExPolygons outer_inner_brim_area(const Print& print, double brimWidthRaw = configBrimWidthByVolumeGroups(adhension, maxSpeed, groupVolumePtrs, volumeGroup.slices, groupHeight); brim_width = scale_(floor(brimWidthRaw / flowWidth / 2) * flowWidth * 2); } + for (const ExPolygon& ex_poly : volumeGroup.slices) { // BBS: additional brim width will be added if part's adhension area is too small and brim is not generated float brim_width_mod; @@ -897,10 +917,25 @@ static ExPolygons outer_inner_brim_area(const Print& print, polygons_reverse(ex_poly_holes_reversed); if (brim_type == BrimType::btOuterOnly || brim_type == BrimType::btOuterAndInner || brim_type == BrimType::btAutoBrim) { + + // BBS: to find whether an island is in a hole of its object + int contour_hole_index = -1; + save_polygon_if_is_inner_island(holes_area, ex_poly.contour, contour_hole_index); + // BBS: inner and outer boundary are offset from the same polygon incase of round off error. auto innerExpoly = offset_ex(ex_poly.contour, brim_offset, jtRound, SCALED_RESOLUTION); - append(brim_area_object, diff_ex(offset_ex(innerExpoly, brim_width_mod, jtRound, SCALED_RESOLUTION), innerExpoly)); + if (contour_hole_index < 0) + append(brim_area_object, diff_ex(offset_ex(innerExpoly, brim_width_mod, jtRound, SCALED_RESOLUTION), innerExpoly)); + else + { + ExPolygons brimBeforeClip = diff_ex(offset_ex(innerExpoly, brim_width_mod, jtRound, SCALED_RESOLUTION), innerExpoly); + + // BBS: an island's brim should not be outside of its belonging hole + Polygons selectedHole = { holes_area[contour_hole_index] }; + ExPolygons clippedBrim = intersection_ex(brimBeforeClip, selectedHole); + append(brim_area_object, clippedBrim); + } } if (brim_type == BrimType::btInnerOnly || brim_type == BrimType::btOuterAndInner) { append(brim_area_object, diff_ex(offset_ex(ex_poly_holes_reversed, -brim_offset), offset_ex(ex_poly_holes_reversed, -brim_width - brim_offset)));