Region.pm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package Slic3r::Layer::Region;
  2. use strict;
  3. use warnings;
  4. use List::Util qw(sum first);
  5. use Slic3r::ExtrusionLoop ':roles';
  6. use Slic3r::ExtrusionPath ':roles';
  7. use Slic3r::Flow ':roles';
  8. use Slic3r::Geometry qw(PI A B scale unscale chained_path points_coincide);
  9. use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex
  10. offset offset_ex offset2 offset2_ex union_pt diff intersection
  11. union diff intersection_ppl diff_ppl);
  12. use Slic3r::Surface ':types';
  13. # TODO: lazy
  14. sub infill_area_threshold {
  15. my $self = shift;
  16. return $self->flow(FLOW_ROLE_SOLID_INFILL)->scaled_spacing ** 2;
  17. }
  18. sub id { return $_[0]->layer->id; }
  19. sub slice_z { return $_[0]->layer->slice_z; }
  20. sub print_z { return $_[0]->layer->print_z; }
  21. sub height { return $_[0]->layer->height; }
  22. sub object { return $_[0]->layer->object; }
  23. sub print { return $_[0]->layer->print; }
  24. sub config { return $_[0]->region->config; }
  25. sub flow {
  26. my ($self, $role, $bridge, $width) = @_;
  27. return $self->region->flow(
  28. $role,
  29. $self->layer->height,
  30. $bridge // 0,
  31. $self->layer->id == 0,
  32. $width,
  33. $self->object,
  34. );
  35. }
  36. sub make_perimeters {
  37. my ($self, $slices, $fill_surfaces) = @_;
  38. # other perimeters
  39. my $perimeter_flow = $self->flow(FLOW_ROLE_PERIMETER);
  40. my $mm3_per_mm = $perimeter_flow->mm3_per_mm;
  41. my $pwidth = $perimeter_flow->scaled_width;
  42. my $pspacing = $perimeter_flow->scaled_spacing;
  43. # external perimeters
  44. my $ext_perimeter_flow = $self->flow(FLOW_ROLE_EXTERNAL_PERIMETER);
  45. my $ext_mm3_per_mm = $ext_perimeter_flow->mm3_per_mm;
  46. my $ext_pwidth = $ext_perimeter_flow->scaled_width;
  47. my $ext_pspacing = scale($ext_perimeter_flow->spacing_to($perimeter_flow));
  48. # overhang perimeters
  49. my $overhang_flow = $self->region->flow(FLOW_ROLE_PERIMETER, -1, 1, 0, undef, $self->layer->object);
  50. my $mm3_per_mm_overhang = $overhang_flow->mm3_per_mm;
  51. # solid infill
  52. my $solid_infill_flow = $self->flow(FLOW_ROLE_SOLID_INFILL);
  53. my $ispacing = $solid_infill_flow->scaled_spacing;
  54. my $gap_area_threshold = $pwidth ** 2;
  55. # Calculate the minimum required spacing between two adjacent traces.
  56. # This should be equal to the nominal flow spacing but we experiment
  57. # with some tolerance in order to avoid triggering medial axis when
  58. # some squishing might work. Loops are still spaced by the entire
  59. # flow spacing; this only applies to collapsing parts.
  60. my $min_spacing = $pspacing * (1 - &Slic3r::INSET_OVERLAP_TOLERANCE);
  61. my $ext_min_spacing = $ext_pspacing * (1 - &Slic3r::INSET_OVERLAP_TOLERANCE);
  62. $self->perimeters->clear;
  63. $self->thin_fills->clear;
  64. my @contours = (); # array of Polygons with ccw orientation
  65. my @holes = (); # array of Polygons with cw orientation
  66. my @thin_walls = (); # array of ExPolygons
  67. # we need to process each island separately because we might have different
  68. # extra perimeters for each one
  69. foreach my $surface (@$slices) {
  70. # detect how many perimeters must be generated for this island
  71. my $loop_number = $self->config->perimeters + ($surface->extra_perimeters || 0);
  72. my @last = @{$surface->expolygon};
  73. my @gaps = (); # array of ExPolygons
  74. if ($loop_number > 0) {
  75. # we loop one time more than needed in order to find gaps after the last perimeter was applied
  76. for my $i (1 .. ($loop_number+1)) { # outer loop is 1
  77. my @offsets = ();
  78. if ($i == 1) {
  79. # the minimum thickness of a single loop is:
  80. # ext_width/2 + ext_spacing/2 + spacing/2 + width/2
  81. @offsets = @{offset2(
  82. \@last,
  83. -(0.5*$ext_pwidth + 0.5*$ext_min_spacing - 1),
  84. +(0.5*$ext_min_spacing - 1),
  85. )};
  86. # look for thin walls
  87. if ($self->config->thin_walls) {
  88. my $diff = diff_ex(
  89. \@last,
  90. offset(\@offsets, +0.5*$ext_pwidth),
  91. 1, # medial axis requires non-overlapping geometry
  92. );
  93. push @thin_walls, @$diff;
  94. }
  95. } else {
  96. my $distance = ($i == 2) ? $ext_pspacing : $pspacing;
  97. @offsets = @{offset2(
  98. \@last,
  99. -($distance + 0.5*$min_spacing - 1),
  100. +(0.5*$min_spacing - 1),
  101. )};
  102. # look for gaps
  103. if ($self->region->config->gap_fill_speed > 0 && $self->config->fill_density > 0) {
  104. # not using safety offset here would "detect" very narrow gaps
  105. # (but still long enough to escape the area threshold) that gap fill
  106. # won't be able to fill but we'd still remove from infill area
  107. my $diff = diff_ex(
  108. offset(\@last, -0.5*$pspacing),
  109. offset(\@offsets, +0.5*$pspacing + 10), # safety offset
  110. );
  111. push @gaps, grep abs($_->area) >= $gap_area_threshold, @$diff;
  112. }
  113. }
  114. last if !@offsets;
  115. last if $i > $loop_number; # we were only looking for gaps this time
  116. # clone polygons because these ExPolygons will go out of scope very soon
  117. @last = @offsets;
  118. foreach my $polygon (@offsets) {
  119. if ($polygon->is_counter_clockwise) {
  120. push @contours, $polygon;
  121. } else {
  122. push @holes, $polygon;
  123. }
  124. }
  125. }
  126. }
  127. # fill gaps
  128. if (@gaps) {
  129. if (0) {
  130. require "Slic3r/SVG.pm";
  131. Slic3r::SVG::output(
  132. "gaps.svg",
  133. expolygons => \@gaps,
  134. );
  135. }
  136. # where $pwidth < thickness < 2*$pspacing, infill with width = 1.5*$pwidth
  137. # where 0.5*$pwidth < thickness < $pwidth, infill with width = 0.5*$pwidth
  138. my @gap_sizes = (
  139. [ $pwidth, 2*$pspacing, unscale 1.5*$pwidth ],
  140. [ 0.5*$pwidth, $pwidth, unscale 0.5*$pwidth ],
  141. );
  142. foreach my $gap_size (@gap_sizes) {
  143. my @gap_fill = $self->_fill_gaps(@$gap_size, \@gaps);
  144. $self->thin_fills->append(@gap_fill);
  145. # Make sure we don't infill narrow parts that are already gap-filled
  146. # (we only consider this surface's gaps to reduce the diff() complexity).
  147. # Growing actual extrusions ensures that gaps not filled by medial axis
  148. # are not subtracted from fill surfaces (they might be too short gaps
  149. # that medial axis skips but infill might join with other infill regions
  150. # and use zigzag).
  151. my $w = $gap_size->[2];
  152. my @filled = map {
  153. @{($_->isa('Slic3r::ExtrusionLoop') ? $_->polygon->split_at_first_point : $_->polyline)
  154. ->grow(scale $w/2)};
  155. } @gap_fill;
  156. @last = @{diff(\@last, \@filled)};
  157. }
  158. }
  159. # create one more offset to be used as boundary for fill
  160. # we offset by half the perimeter spacing (to get to the actual infill boundary)
  161. # and then we offset back and forth by half the infill spacing to only consider the
  162. # non-collapsing regions
  163. my $min_perimeter_infill_spacing = $ispacing * (1 - &Slic3r::INSET_OVERLAP_TOLERANCE);
  164. $fill_surfaces->append(
  165. map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNAL), # use a bogus surface type
  166. @{offset2_ex(
  167. [ map @{$_->simplify_p(&Slic3r::SCALED_RESOLUTION)}, @{union_ex(\@last)} ],
  168. -($pspacing/2 + $min_perimeter_infill_spacing/2),
  169. +$min_perimeter_infill_spacing/2,
  170. )}
  171. );
  172. }
  173. # process thin walls by collapsing slices to single passes
  174. my @thin_wall_polylines = ();
  175. if (@thin_walls) {
  176. # the following offset2 ensures almost nothing in @thin_walls is narrower than $min_width
  177. # (actually, something larger than that still may exist due to mitering or other causes)
  178. my $min_width = $pwidth / 4;
  179. @thin_walls = @{offset2_ex([ map @$_, @thin_walls ], -$min_width/2, +$min_width/2)};
  180. # the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop
  181. @thin_wall_polylines = map @{$_->medial_axis($pwidth + $pspacing, $min_width)}, @thin_walls;
  182. Slic3r::debugf " %d thin walls detected\n", scalar(@thin_wall_polylines) if $Slic3r::debug;
  183. if (0) {
  184. require "Slic3r/SVG.pm";
  185. Slic3r::SVG::output(
  186. "medial_axis.svg",
  187. no_arrows => 1,
  188. expolygons => \@thin_walls,
  189. green_polylines => [ map $_->polygon->split_at_first_point, @{$self->perimeters} ],
  190. red_polylines => \@thin_wall_polylines,
  191. );
  192. }
  193. }
  194. # find nesting hierarchies separately for contours and holes
  195. my $contours_pt = union_pt(\@contours);
  196. my $holes_pt = union_pt(\@holes);
  197. # prepare grown lower layer slices for overhang detection
  198. my $lower_slices = Slic3r::ExPolygon::Collection->new;
  199. if ($self->layer->lower_layer && $self->region->config->overhangs) {
  200. # We consider overhang any part where the entire nozzle diameter is not supported by the
  201. # lower layer, so we take lower slices and offset them by half the nozzle diameter used
  202. # in the current layer
  203. my $nozzle_diameter = $self->layer->print->config->get_at('nozzle_diameter', $self->region->config->perimeter_extruder-1);
  204. $lower_slices->append(
  205. @{offset_ex([ map @$_, @{$self->layer->lower_layer->slices} ], scale +$nozzle_diameter/2)},
  206. );
  207. }
  208. my $lower_slices_p = $lower_slices->polygons;
  209. # prepare a coderef for traversing the PolyTree object
  210. # external contours are root items of $contours_pt
  211. # internal contours are the ones next to external
  212. my $traverse;
  213. $traverse = sub {
  214. my ($polynodes, $depth, $is_contour) = @_;
  215. # convert all polynodes to ExtrusionLoop objects
  216. my $collection = Slic3r::ExtrusionPath::Collection->new;
  217. my @children = ();
  218. foreach my $polynode (@$polynodes) {
  219. my $polygon = ($polynode->{outer} // $polynode->{hole})->clone;
  220. my $role = EXTR_ROLE_PERIMETER;
  221. my $loop_role = EXTRL_ROLE_DEFAULT;
  222. my $root_level = $depth == 0;
  223. my $no_children = !@{ $polynode->{children} };
  224. my $is_external = $is_contour ? $root_level : $no_children;
  225. my $is_internal = $is_contour ? $no_children : $root_level;
  226. if ($is_external) {
  227. # external perimeters are root level in case of contours
  228. # and items with no children in case of holes
  229. $role = EXTR_ROLE_EXTERNAL_PERIMETER;
  230. $loop_role = EXTRL_ROLE_EXTERNAL_PERIMETER;
  231. } elsif ($is_contour && $is_internal) {
  232. # internal perimeters are root level in case of holes
  233. # and items with no children in case of contours
  234. $loop_role = EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER;
  235. }
  236. # detect overhanging/bridging perimeters
  237. my @paths = ();
  238. if ($self->region->config->overhangs && $lower_slices->count > 0) {
  239. # get non-overhang paths by intersecting this loop with the grown lower slices
  240. foreach my $polyline (@{ intersection_ppl([ $polygon ], $lower_slices_p) }) {
  241. push @paths, Slic3r::ExtrusionPath->new(
  242. polyline => $polyline,
  243. role => $role,
  244. mm3_per_mm => ($is_external ? $ext_mm3_per_mm : $mm3_per_mm),
  245. width => ($is_external ? $ext_perimeter_flow->width : $perimeter_flow->width),
  246. height => $self->height,
  247. );
  248. }
  249. # get overhang paths by checking what parts of this loop fall
  250. # outside the grown lower slices (thus where the distance between
  251. # the loop centerline and original lower slices is >= half nozzle diameter
  252. foreach my $polyline (@{ diff_ppl([ $polygon ], $lower_slices_p) }) {
  253. push @paths, Slic3r::ExtrusionPath->new(
  254. polyline => $polyline,
  255. role => EXTR_ROLE_OVERHANG_PERIMETER,
  256. mm3_per_mm => $mm3_per_mm_overhang,
  257. width => $overhang_flow->width,
  258. height => $self->height,
  259. );
  260. }
  261. # reapply the nearest point search for starting point
  262. # (clone because the collection gets DESTROY'ed)
  263. # We allow polyline reversal because Clipper may have randomly
  264. # reversed polylines during clipping.
  265. my $collection = Slic3r::ExtrusionPath::Collection->new(@paths);
  266. @paths = map $_->clone, @{$collection->chained_path(0)};
  267. } else {
  268. push @paths, Slic3r::ExtrusionPath->new(
  269. polyline => $polygon->split_at_first_point,
  270. role => $role,
  271. mm3_per_mm => $mm3_per_mm,
  272. width => $perimeter_flow->width,
  273. height => $self->height,
  274. );
  275. }
  276. my $loop = Slic3r::ExtrusionLoop->new_from_paths(@paths);
  277. $loop->role($loop_role);
  278. # return ccw contours and cw holes
  279. # GCode.pm will convert all of them to ccw, but it needs to know
  280. # what the holes are in order to compute the correct inwards move
  281. # We do this on the final Loop object instead of the polygon because
  282. # overhang clipping might have reversed its order since Clipper does
  283. # not preserve polyline orientation.
  284. if ($is_contour) {
  285. $loop->make_counter_clockwise;
  286. } else {
  287. $loop->make_clockwise;
  288. }
  289. $collection->append($loop);
  290. # save the children
  291. push @children, $polynode->{children};
  292. }
  293. # if we're handling the top-level contours, add thin walls as candidates too
  294. # in order to include them in the nearest-neighbor search
  295. if ($is_contour && $depth == 0) {
  296. foreach my $polyline (@thin_wall_polylines) {
  297. $collection->append(Slic3r::ExtrusionPath->new(
  298. polyline => $polyline,
  299. role => EXTR_ROLE_EXTERNAL_PERIMETER,
  300. mm3_per_mm => $mm3_per_mm,
  301. width => $perimeter_flow->width,
  302. height => $self->height,
  303. ));
  304. }
  305. }
  306. # use a nearest neighbor search to order these children
  307. # TODO: supply second argument to chained_path() too?
  308. # Optimization: since islands are going to be sorted by slice anyway in the
  309. # G-code export process, we skip chained_path here
  310. my ($sorted_collection, @orig_indices);
  311. if ($is_contour && $depth == 0) {
  312. $sorted_collection = $collection;
  313. @orig_indices = (0..$#$sorted_collection);
  314. } else {
  315. $sorted_collection = $collection->chained_path_indices(0);
  316. @orig_indices = @{$sorted_collection->orig_indices};
  317. }
  318. my @loops = ();
  319. foreach my $loop (@$sorted_collection) {
  320. my $orig_index = shift @orig_indices;
  321. if ($loop->isa('Slic3r::ExtrusionPath')) {
  322. push @loops, $loop->clone;
  323. } else {
  324. # if this is an external contour find all holes belonging to this contour(s)
  325. # and prepend them
  326. if ($is_contour && $depth == 0) {
  327. # $loop is the outermost loop of an island
  328. my @holes = ();
  329. for (my $i = 0; $i <= $#$holes_pt; $i++) {
  330. if ($loop->polygon->contains_point($holes_pt->[$i]{outer}->first_point)) {
  331. push @holes, splice @$holes_pt, $i, 1; # remove from candidates to reduce complexity
  332. $i--;
  333. }
  334. }
  335. # order holes efficiently
  336. @holes = @holes[@{chained_path([ map {($_->{outer} // $_->{hole})->first_point} @holes ])}];
  337. push @loops, reverse map $traverse->([$_], 0, 0), @holes;
  338. }
  339. # traverse children and prepend them to this loop
  340. push @loops, $traverse->($children[$orig_index], $depth+1, $is_contour);
  341. push @loops, $loop->clone;
  342. }
  343. }
  344. return @loops;
  345. };
  346. # order loops from inner to outer (in terms of object slices)
  347. my @loops = $traverse->($contours_pt, 0, 1);
  348. # if brim will be printed, reverse the order of perimeters so that
  349. # we continue inwards after having finished the brim
  350. # TODO: add test for perimeter order
  351. @loops = reverse @loops
  352. if $self->region->config->external_perimeters_first
  353. || ($self->layer->id == 0 && $self->print->config->brim_width > 0);
  354. # append perimeters
  355. $self->perimeters->append(@loops);
  356. }
  357. sub _fill_gaps {
  358. my ($self, $min, $max, $w, $gaps) = @_;
  359. my $this = diff_ex(
  360. offset2([ map @$_, @$gaps ], -$min/2, +$min/2),
  361. offset2([ map @$_, @$gaps ], -$max/2, +$max/2),
  362. 1,
  363. );
  364. my $flow = $self->flow(FLOW_ROLE_SOLID_INFILL, 0, $w);
  365. my %path_args = (
  366. role => EXTR_ROLE_GAPFILL,
  367. mm3_per_mm => $flow->mm3_per_mm,
  368. width => $flow->width,
  369. height => $self->height,
  370. );
  371. my @polylines = map @{$_->medial_axis($max, $min/2)}, @$this;
  372. Slic3r::debugf " %d gaps filled with extrusion width = %s\n", scalar @$this, $w
  373. if @$this;
  374. for my $i (0..$#polylines) {
  375. if ($polylines[$i]->isa('Slic3r::Polygon')) {
  376. my $loop = Slic3r::ExtrusionLoop->new;
  377. $loop->append(Slic3r::ExtrusionPath->new(polyline => $polylines[$i]->split_at_first_point, %path_args));
  378. $polylines[$i] = $loop;
  379. } elsif ($polylines[$i]->is_valid && $polylines[$i]->first_point->coincides_with($polylines[$i]->last_point)) {
  380. # since medial_axis() now returns only Polyline objects, detect loops here
  381. my $loop = Slic3r::ExtrusionLoop->new;
  382. $loop->append(Slic3r::ExtrusionPath->new(polyline => $polylines[$i], %path_args));
  383. $polylines[$i] = $loop;
  384. } else {
  385. $polylines[$i] = Slic3r::ExtrusionPath->new(polyline => $polylines[$i], %path_args);
  386. }
  387. }
  388. return @polylines;
  389. }
  390. sub prepare_fill_surfaces {
  391. my $self = shift;
  392. # Note: in order to make the psPrepareInfill step idempotent, we should never
  393. # alter fill_surfaces boundaries on which our idempotency relies since that's
  394. # the only meaningful information returned by psPerimeters.
  395. # if no solid layers are requested, turn top/bottom surfaces to internal
  396. if ($self->config->top_solid_layers == 0) {
  397. $_->surface_type(S_TYPE_INTERNAL) for @{$self->fill_surfaces->filter_by_type(S_TYPE_TOP)};
  398. }
  399. if ($self->config->bottom_solid_layers == 0) {
  400. $_->surface_type(S_TYPE_INTERNAL)
  401. for @{$self->fill_surfaces->filter_by_type(S_TYPE_BOTTOM)}, @{$self->fill_surfaces->filter_by_type(S_TYPE_BOTTOMBRIDGE)};
  402. }
  403. # turn too small internal regions into solid regions according to the user setting
  404. if ($self->config->fill_density > 0) {
  405. my $min_area = scale scale $self->config->solid_infill_below_area; # scaling an area requires two calls!
  406. $_->surface_type(S_TYPE_INTERNALSOLID)
  407. for grep { $_->area <= $min_area } @{$self->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)};
  408. }
  409. }
  410. sub process_external_surfaces {
  411. my ($self, $lower_layer) = @_;
  412. my @surfaces = @{$self->fill_surfaces};
  413. my $margin = scale &Slic3r::EXTERNAL_INFILL_MARGIN;
  414. my @bottom = ();
  415. foreach my $surface (grep $_->is_bottom, @surfaces) {
  416. my $grown = $surface->expolygon->offset_ex(+$margin);
  417. # detect bridge direction before merging grown surfaces otherwise adjacent bridges
  418. # would get merged into a single one while they need different directions
  419. # also, supply the original expolygon instead of the grown one, because in case
  420. # of very thin (but still working) anchors, the grown expolygon would go beyond them
  421. my $angle;
  422. if ($lower_layer) {
  423. my $bridge_detector = Slic3r::Layer::BridgeDetector->new(
  424. expolygon => $surface->expolygon,
  425. lower_slices => $lower_layer->slices,
  426. extrusion_width => $self->flow(FLOW_ROLE_INFILL, $self->height, 1)->scaled_width,
  427. );
  428. Slic3r::debugf "Processing bridge at layer %d:\n", $self->id;
  429. $angle = $bridge_detector->detect_angle;
  430. if (defined $angle && $self->object->config->support_material) {
  431. $self->bridged->append(@{ $bridge_detector->coverage($angle) });
  432. $self->unsupported_bridge_edges->append(@{ $bridge_detector->unsupported_edges });
  433. }
  434. }
  435. push @bottom, map $surface->clone(expolygon => $_, bridge_angle => $angle), @$grown;
  436. }
  437. my @top = ();
  438. foreach my $surface (grep $_->surface_type == S_TYPE_TOP, @surfaces) {
  439. # give priority to bottom surfaces
  440. my $grown = diff_ex(
  441. $surface->expolygon->offset(+$margin),
  442. [ map $_->p, @bottom ],
  443. );
  444. push @top, map $surface->clone(expolygon => $_), @$grown;
  445. }
  446. # if we're slicing with no infill, we can't extend external surfaces
  447. # over non-existent infill
  448. my @fill_boundaries = $self->config->fill_density > 0
  449. ? @surfaces
  450. : grep $_->surface_type != S_TYPE_INTERNAL, @surfaces;
  451. # intersect the grown surfaces with the actual fill boundaries
  452. my @new_surfaces = ();
  453. foreach my $group (@{Slic3r::Surface::Collection->new(@top, @bottom)->group}) {
  454. push @new_surfaces,
  455. map $group->[0]->clone(expolygon => $_),
  456. @{intersection_ex(
  457. [ map $_->p, @$group ],
  458. [ map $_->p, @fill_boundaries ],
  459. 1, # to ensure adjacent expolygons are unified
  460. )};
  461. }
  462. # subtract the new top surfaces from the other non-top surfaces and re-add them
  463. my @other = grep $_->surface_type != S_TYPE_TOP && !$_->is_bottom, @surfaces;
  464. foreach my $group (@{Slic3r::Surface::Collection->new(@other)->group}) {
  465. push @new_surfaces, map $group->[0]->clone(expolygon => $_), @{diff_ex(
  466. [ map $_->p, @$group ],
  467. [ map $_->p, @new_surfaces ],
  468. )};
  469. }
  470. $self->fill_surfaces->clear;
  471. $self->fill_surfaces->append(@new_surfaces);
  472. }
  473. 1;