SupportMaterial.pm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. package Slic3r::Print::SupportMaterial;
  2. use Moo;
  3. use List::Util qw(sum min max);
  4. use Slic3r::ExtrusionPath ':roles';
  5. use Slic3r::Geometry qw(scale scaled_epsilon PI rad2deg deg2rad);
  6. use Slic3r::Geometry::Clipper qw(offset diff union union_ex intersection offset_ex offset2
  7. intersection_pl);
  8. use Slic3r::Surface ':types';
  9. has 'config' => (is => 'rw', required => 1);
  10. has 'flow' => (is => 'rw', required => 1);
  11. use constant DEBUG_CONTACT_ONLY => 0;
  12. # how much we extend support around the actual contact area
  13. use constant MARGIN => 1.5;
  14. # increment used to reach MARGIN in steps to avoid trespassing thin objects
  15. use constant MARGIN_STEP => MARGIN/3;
  16. sub generate {
  17. my ($self, $object) = @_;
  18. # Determine the top surfaces of the support, defined as:
  19. # contact = overhangs - clearance + margin
  20. # This method is responsible for identifying what contact surfaces
  21. # should the support material expose to the object in order to guarantee
  22. # that it will be effective, regardless of how it's built below.
  23. my ($contact, $overhang) = $self->contact_area($object);
  24. # Determine the top surfaces of the object. We need these to determine
  25. # the layer heights of support material and to clip support to the object
  26. # silhouette.
  27. my ($top) = $self->object_top($object, $contact);
  28. # We now know the upper and lower boundaries for our support material object
  29. # (@$contact_z and @$top_z), so we can generate intermediate layers.
  30. my ($support_z) = $self->support_layers_z(
  31. [ sort keys %$contact ],
  32. [ sort keys %$top ],
  33. max(map $_->height, @{$object->layers})
  34. );
  35. # If we wanted to apply some special logic to the first support layers lying on
  36. # object's top surfaces this is the place to detect them
  37. # Propagate contact layers downwards to generate interface layers
  38. my ($interface) = $self->generate_interface_layers($support_z, $contact, $top);
  39. $self->clip_with_object($interface, $support_z, $object);
  40. # Propagate contact layers and interface layers downwards to generate
  41. # the main support layers.
  42. my ($base) = $self->generate_base_layers($support_z, $contact, $interface, $top);
  43. $self->clip_with_object($base, $support_z, $object);
  44. # Install support layers into object.
  45. push @{$object->support_layers}, map Slic3r::Layer::Support->new(
  46. object => $object,
  47. id => $_,
  48. height => ($_ == 0) ? $support_z->[$_] : ($support_z->[$_] - $support_z->[$_-1]),
  49. print_z => $support_z->[$_],
  50. slice_z => -1,
  51. slices => [],
  52. ), 0 .. $#$support_z;
  53. # Generate the actual toolpaths and save them into each layer.
  54. $self->generate_toolpaths($object, $overhang, $contact, $interface, $base);
  55. }
  56. sub contact_area {
  57. my ($self, $object) = @_;
  58. # if user specified a custom angle threshold, convert it to radians
  59. my $threshold_rad;
  60. if ($self->config->support_material_threshold) {
  61. $threshold_rad = deg2rad($self->config->support_material_threshold + 1); # +1 makes the threshold inclusive
  62. Slic3r::debugf "Threshold angle = %d°\n", rad2deg($threshold_rad);
  63. }
  64. # determine contact areas
  65. my %contact = (); # contact_z => [ polygons ]
  66. my %overhang = (); # contact_z => [ polygons ] - this stores the actual overhang supported by each contact layer
  67. for my $layer_id (0 .. $#{$object->layers}) {
  68. if ($self->config->raft_layers == 0) {
  69. next if $layer_id == 0;
  70. } elsif (!$self->config->support_material) {
  71. # if we are only going to generate raft just check
  72. # the 'overhangs' of the first object layer
  73. last if $layer_id > 0;
  74. }
  75. my $layer = $object->layers->[$layer_id];
  76. my $lower_layer = $object->layers->[$layer_id-1];
  77. # detect overhangs and contact areas needed to support them
  78. my (@overhang, @contact) = ();
  79. foreach my $layerm (@{$layer->regions}) {
  80. my $fw = $layerm->perimeter_flow->scaled_width;
  81. my $diff;
  82. # If a threshold angle was specified, use a different logic for detecting overhangs.
  83. if (defined $threshold_rad
  84. || $layer_id < $self->config->support_material_enforce_layers
  85. || $self->config->raft_layers > 0) {
  86. my $d = defined $threshold_rad
  87. ? scale $lower_layer->height * ((cos $threshold_rad) / (sin $threshold_rad))
  88. : 0;
  89. $diff = diff(
  90. offset([ map $_->p, @{$layerm->slices} ], -$d),
  91. [ map @$_, @{$lower_layer->slices} ],
  92. );
  93. # only enforce spacing from the object ($fw/2) if the threshold angle
  94. # is not too high: in that case, $d will be very small (as we need to catch
  95. # very short overhangs), and such contact area would be eaten by the
  96. # enforced spacing, resulting in high threshold angles to be almost ignored
  97. $diff = diff(
  98. offset($diff, $d - $fw/2),
  99. [ map @$_, @{$lower_layer->slices} ],
  100. ) if $d > $fw/2;
  101. } else {
  102. $diff = diff(
  103. offset([ map $_->p, @{$layerm->slices} ], -$fw/2),
  104. [ map @$_, @{$lower_layer->slices} ],
  105. );
  106. # collapse very tiny spots
  107. $diff = offset2($diff, -$fw/10, +$fw/10);
  108. # $diff now contains the ring or stripe comprised between the boundary of
  109. # lower slices and the centerline of the last perimeter in this overhanging layer.
  110. # Void $diff means that there's no upper perimeter whose centerline is
  111. # outside the lower slice boundary, thus no overhang
  112. }
  113. # TODO: this is the place to remove bridged areas
  114. next if !@$diff;
  115. push @overhang, @$diff; # NOTE: this is not the full overhang as it misses the outermost half of the perimeter width!
  116. # Let's define the required contact area by using a max gap of half the upper
  117. # extrusion width and extending the area according to the configured margin.
  118. # We increment the area in steps because we don't want our support to overflow
  119. # on the other side of the object (if it's very thin).
  120. {
  121. my @slices_margin = @{offset([ map @$_, @{$lower_layer->slices} ], $fw/2)};
  122. for ($fw/2, map {scale MARGIN_STEP} 1..(MARGIN / MARGIN_STEP)) {
  123. $diff = diff(
  124. offset($diff, $_),
  125. \@slices_margin,
  126. );
  127. }
  128. }
  129. push @contact, @$diff;
  130. }
  131. next if !@contact;
  132. # now apply the contact areas to the layer were they need to be made
  133. {
  134. # get the average nozzle diameter used on this layer
  135. my @nozzle_diameters = map $_->nozzle_diameter,
  136. map { $_->perimeter_flow, $_->solid_infill_flow }
  137. @{$layer->regions};
  138. my $nozzle_diameter = sum(@nozzle_diameters)/@nozzle_diameters;
  139. my $contact_z = $layer->print_z - $nozzle_diameter * 1.5;
  140. ###$contact_z = $layer->print_z - $layer->height;
  141. # ignore this contact area if it's too low
  142. next if $contact_z < $Slic3r::Config->get_value('first_layer_height');
  143. $contact{$contact_z} = [ @contact ];
  144. $overhang{$contact_z} = [ @overhang ];
  145. if (0) {
  146. require "Slic3r/SVG.pm";
  147. Slic3r::SVG::output("contact_" . $contact_z . ".svg",
  148. expolygons => union_ex(\@contact),
  149. red_expolygons => \@overhang,
  150. );
  151. }
  152. }
  153. }
  154. return (\%contact, \%overhang);
  155. }
  156. sub object_top {
  157. my ($self, $object, $contact) = @_;
  158. # find object top surfaces
  159. # we'll use them to clip our support and detect where does it stick
  160. my %top = (); # print_z => [ expolygons ]
  161. my $projection = [];
  162. foreach my $layer (reverse @{$object->layers}) {
  163. if (my @top = map @{$_->slices->filter_by_type(S_TYPE_TOP)}, @{$layer->regions}) {
  164. # compute projection of the contact areas above this top layer
  165. # first add all the 'new' contact areas to the current projection
  166. # ('new' means all the areas that are lower than the last top layer
  167. # we considered)
  168. my $min_top = min(keys %top) // max(keys %$contact);
  169. # use <= instead of just < because otherwise we'd ignore any contact regions
  170. # having the same Z of top layers
  171. push @$projection, map @{$contact->{$_}}, grep { $_ > $layer->print_z && $_ <= $min_top } keys %$contact;
  172. # now find whether any projection falls onto this top surface
  173. my $touching = intersection($projection, [ map $_->p, @top ]);
  174. if (@$touching) {
  175. # grow top surfaces so that interface and support generation are generated
  176. # with some spacing from object - it looks we don't need the actual
  177. # top shapes so this can be done here
  178. $top{ $layer->print_z } = offset($touching, $self->flow->scaled_width);
  179. }
  180. # remove the areas that touched from the projection that will continue on
  181. # next, lower, top surfaces
  182. $projection = diff($projection, $touching);
  183. }
  184. }
  185. return \%top;
  186. }
  187. sub support_layers_z {
  188. my ($self, $contact_z, $top_z, $max_object_layer_height) = @_;
  189. # quick table to check whether a given Z is a top surface
  190. my %top = map { $_ => 1 } @$top_z;
  191. # determine layer height for any non-contact layer
  192. # we use max() to prevent many ultra-thin layers to be inserted in case
  193. # layer_height > nozzle_diameter * 0.75
  194. my $nozzle_diameter = $self->flow->nozzle_diameter;
  195. my $support_material_height = max($max_object_layer_height, $nozzle_diameter * 0.75);
  196. my @z = sort { $a <=> $b } @$contact_z, @$top_z, (map $_ + $nozzle_diameter, @$top_z);
  197. # enforce first layer height
  198. my $first_layer_height = $self->config->get_value('first_layer_height');
  199. shift @z while @z && $z[0] <= $first_layer_height;
  200. unshift @z, $first_layer_height;
  201. # add raft layers by dividing the space between first layer and
  202. # first contact layer evenly
  203. if ($self->config->raft_layers > 1 && @z >= 2) {
  204. # $z[1] is last raft layer (contact layer for the first layer object)
  205. my $height = ($z[1] - $z[0]) / ($self->config->raft_layers - 1);
  206. splice @z, 1, 0,
  207. map { int($_*100)/100 }
  208. map { $z[0] + $height * $_ }
  209. 0..($self->config->raft_layers - 1);
  210. }
  211. for (my $i = $#z; $i >= 0; $i--) {
  212. my $target_height = $support_material_height;
  213. if ($i > 0 && $top{ $z[$i-1] }) {
  214. $target_height = $nozzle_diameter;
  215. }
  216. # enforce first layer height
  217. if (($i == 0 && $z[$i] > $target_height + $first_layer_height)
  218. || ($z[$i] - $z[$i-1] > $target_height + Slic3r::Geometry::epsilon)) {
  219. splice @z, $i, 0, ($z[$i] - $target_height);
  220. $i++;
  221. }
  222. }
  223. # remove duplicates and make sure all 0.x values have the leading 0
  224. {
  225. my %sl = map { 1 * $_ => 1 } @z;
  226. @z = sort { $a <=> $b } keys %sl;
  227. }
  228. return \@z;
  229. }
  230. sub generate_interface_layers {
  231. my ($self, $support_z, $contact, $top) = @_;
  232. # let's now generate interface layers below contact areas
  233. my %interface = (); # layer_id => [ polygons ]
  234. my $interface_layers = $self->config->support_material_interface_layers;
  235. for my $layer_id (0 .. $#$support_z) {
  236. my $z = $support_z->[$layer_id];
  237. my $this = $contact->{$z} // next;
  238. # count contact layer as interface layer
  239. for (my $i = $layer_id-1; $i >= 0 && $i > $layer_id-$interface_layers; $i--) {
  240. $z = $support_z->[$i];
  241. my @overlapping_layers = $self->overlapping_layers($i, $support_z);
  242. my @overlapping_z = map $support_z->[$_], @overlapping_layers;
  243. # Compute interface area on this layer as diff of upper contact area
  244. # (or upper interface area) and layer slices.
  245. # This diff is responsible of the contact between support material and
  246. # the top surfaces of the object. We should probably offset the top
  247. # surfaces vertically before performing the diff, but this needs
  248. # investigation.
  249. $this = $interface{$i} = diff(
  250. [
  251. @$this, # clipped projection of the current contact regions
  252. @{ $interface{$i} || [] }, # interface regions already applied to this layer
  253. ],
  254. [
  255. (map @$_, map $top->{$_}, grep exists $top->{$_}, @overlapping_z), # top slices on this layer
  256. (map @$_, map $contact->{$_}, grep exists $contact->{$_}, @overlapping_z), # contact regions on this layer
  257. ],
  258. 1,
  259. );
  260. }
  261. }
  262. return \%interface;
  263. }
  264. sub generate_base_layers {
  265. my ($self, $support_z, $contact, $interface, $top) = @_;
  266. # let's now generate support layers under interface layers
  267. my $base = {}; # layer_id => [ polygons ]
  268. {
  269. for my $i (reverse 0 .. $#$support_z-1) {
  270. my $z = $support_z->[$i];
  271. my @overlapping_layers = $self->overlapping_layers($i, $support_z);
  272. my @overlapping_z = map $support_z->[$_], @overlapping_layers;
  273. # in case we have no interface layers, look at upper contact
  274. # (1 interface layer means we only have contact layer, so $interface->{$i+1} is empty)
  275. my @upper_contact = ();
  276. if ($self->config->support_material_interface_layers <= 1) {
  277. @upper_contact = @{ $contact->{$support_z->[$i+1]} || [] };
  278. }
  279. $base->{$i} = diff(
  280. [
  281. @{ $base->{$i+1} || [] }, # support regions on upper layer
  282. @{ $interface->{$i+1} || [] }, # interface regions on upper layer
  283. @upper_contact, # contact regions on upper layer
  284. ],
  285. [
  286. (map @$_, map $top->{$_}, grep exists $top->{$_}, @overlapping_z), # top slices on this layer
  287. (map @$_, map $interface->{$_}, grep exists $interface->{$_}, @overlapping_layers), # interface regions on this layer
  288. (map @$_, map $contact->{$_}, grep exists $contact->{$_}, @overlapping_z), # contact regions on this layer
  289. ],
  290. 1,
  291. );
  292. }
  293. }
  294. return $base;
  295. }
  296. sub clip_with_object {
  297. my ($self, $support, $support_z, $object) = @_;
  298. foreach my $i (keys %$support) {
  299. next if !@{$support->{$i}};
  300. my $zmax = $support_z->[$i];
  301. my $zmin = ($i == 0) ? 0 : $support_z->[$i-1];
  302. my @layers = grep { $_->print_z > $zmin && ($_->print_z - $_->height) < $zmax }
  303. @{$object->layers};
  304. $support->{$i} = diff(
  305. $support->{$i},
  306. offset([ map @$_, map @{$_->slices}, @layers ], +$self->flow->scaled_width),
  307. );
  308. }
  309. }
  310. sub generate_toolpaths {
  311. my ($self, $object, $overhang, $contact, $interface, $base) = @_;
  312. my $flow = $self->flow;
  313. # shape of contact area
  314. my $contact_loops = 1;
  315. my $circle_radius = 1.5 * $flow->scaled_width;
  316. my $circle_distance = 3 * $circle_radius;
  317. my $circle = Slic3r::Polygon->new(map [ $circle_radius * cos $_, $circle_radius * sin $_ ],
  318. (5*PI/3, 4*PI/3, PI, 2*PI/3, PI/3, 0));
  319. Slic3r::debugf "Generating patterns\n";
  320. # prepare fillers
  321. my $pattern = $self->config->support_material_pattern;
  322. my @angles = ($self->config->support_material_angle);
  323. if ($pattern eq 'rectilinear-grid') {
  324. $pattern = 'rectilinear';
  325. push @angles, $angles[0] + 90;
  326. }
  327. my %fillers = (
  328. interface => $object->fill_maker->filler('rectilinear'),
  329. support => $object->fill_maker->filler($pattern),
  330. );
  331. my $interface_angle = $self->config->support_material_angle + 90;
  332. my $interface_spacing = $self->config->support_material_interface_spacing + $flow->spacing;
  333. my $interface_density = $interface_spacing == 0 ? 1 : $flow->spacing / $interface_spacing;
  334. my $support_spacing = $self->config->support_material_spacing + $flow->spacing;
  335. my $support_density = $support_spacing == 0 ? 1 : $flow->spacing / $support_spacing;
  336. my $process_layer = sub {
  337. my ($layer_id) = @_;
  338. my $layer = $object->support_layers->[$layer_id];
  339. my $z = $layer->print_z;
  340. my $overhang = $overhang->{$z} || [];
  341. my $contact = $contact->{$z} || [];
  342. my $interface = $interface->{$layer_id} || [];
  343. my $base = $base->{$layer_id} || [];
  344. if (DEBUG_CONTACT_ONLY) {
  345. $interface = [];
  346. $base = [];
  347. }
  348. if (0) {
  349. require "Slic3r/SVG.pm";
  350. Slic3r::SVG::output("layer_" . $z . ".svg",
  351. red_expolygons => union_ex($contact),
  352. green_expolygons => union_ex($interface),
  353. );
  354. }
  355. # islands
  356. $layer->support_islands->append(@{union_ex([ @$interface, @$base, @$contact ])});
  357. # contact
  358. my $contact_infill = [];
  359. if ($self->config->support_material_interface_layers == 0) {
  360. # if no interface layers were requested we treat the contact layer
  361. # exactly as a generic base layer
  362. push @$base, @$contact;
  363. } elsif (@$contact && $contact_loops > 0) {
  364. # generate the outermost loop
  365. my @loops0 = ();
  366. {
  367. # find centerline of the external loop of the contours
  368. my @external_loops = @{offset($contact, -$flow->scaled_width/2)};
  369. # only consider the loops facing the overhang
  370. {
  371. my $overhang_with_margin = offset($overhang, +$flow->scaled_width/2);
  372. @external_loops = grep {
  373. @{intersection_pl(
  374. [ $_->split_at_first_point ],
  375. $overhang_with_margin,
  376. )}
  377. } @external_loops;
  378. }
  379. # apply a pattern to the loop
  380. my @positions = map @{Slic3r::Polygon->new(@$_)->equally_spaced_points($circle_distance)}, @external_loops;
  381. @loops0 = @{diff(
  382. [ @external_loops ],
  383. [ map { my $c = $circle->clone; $c->translate(@$_); $c } @positions ],
  384. )};
  385. }
  386. # make more loops
  387. my @loops = @loops0;
  388. for my $i (2..$contact_loops) {
  389. my $d = ($i-1) * $flow->scaled_spacing;
  390. push @loops, @{offset2(\@loops0, -$d -0.5*$flow->scaled_spacing, +0.5*$flow->scaled_spacing)};
  391. }
  392. # clip such loops to the side oriented towards the object
  393. @loops = @{intersection_pl(
  394. [ map $_->split_at_first_point, @loops ],
  395. offset($overhang, +scale MARGIN),
  396. )};
  397. # add the contact infill area to the interface area
  398. # note that growing loops by $circle_radius ensures no tiny
  399. # extrusions are left inside the circles; however it creates
  400. # a very large gap between loops and contact_infill, so maybe another
  401. # solution should be found to achieve both goals
  402. $contact_infill = diff(
  403. $contact,
  404. [ map @{$_->grow($circle_radius*1.1)}, @loops ],
  405. );
  406. # transform loops into ExtrusionPath objects
  407. @loops = map Slic3r::ExtrusionPath->new(
  408. polyline => $_,
  409. role => EXTR_ROLE_SUPPORTMATERIAL,
  410. flow_spacing => $flow->spacing,
  411. ), @loops;
  412. $layer->support_interface_fills->append(@loops);
  413. }
  414. # interface and contact infill
  415. if (@$interface || @$contact_infill) {
  416. $fillers{interface}->angle($interface_angle);
  417. # join regions by offsetting them to ensure they're merged
  418. $interface = offset([ @$interface, @$contact_infill ], scaled_epsilon);
  419. # turn base support into interface when it's contained in our holes
  420. # (this way we get wider interface anchoring)
  421. {
  422. my @p = @$interface;
  423. @$interface = ();
  424. foreach my $p (@p) {
  425. if ($p->is_clockwise) {
  426. my $p2 = $p->clone;
  427. $p2->make_counter_clockwise;
  428. next if !@{diff([$p2], $base, 1)};
  429. }
  430. push @$interface, $p;
  431. }
  432. }
  433. $base = diff($base, $interface);
  434. my @paths = ();
  435. foreach my $expolygon (@{union_ex($interface)}) {
  436. my ($params, @p) = $fillers{interface}->fill_surface(
  437. Slic3r::Surface->new(expolygon => $expolygon, surface_type => S_TYPE_INTERNAL),
  438. density => $interface_density,
  439. flow_spacing => $flow->spacing,
  440. complete => 1,
  441. );
  442. push @paths, map Slic3r::ExtrusionPath->new(
  443. polyline => Slic3r::Polyline->new(@$_),
  444. role => EXTR_ROLE_SUPPORTMATERIAL,
  445. height => undef,
  446. flow_spacing => $params->{flow_spacing},
  447. ), @p;
  448. }
  449. $layer->support_interface_fills->append(@paths);
  450. }
  451. # support or flange
  452. if (@$base) {
  453. my $filler = $fillers{support};
  454. $filler->angle($angles[ ($layer_id) % @angles ]);
  455. my $density = $support_density;
  456. my $flow_spacing = $flow->spacing;
  457. # TODO: use offset2_ex()
  458. my $to_infill = union_ex($base, 1);
  459. my @paths = ();
  460. # base flange
  461. if ($layer_id == 0) {
  462. $filler = $fillers{interface};
  463. $filler->angle($self->config->support_material_angle + 90);
  464. $density = 0.5;
  465. $flow_spacing = $object->print->first_layer_support_material_flow->spacing;
  466. } else {
  467. # draw a perimeter all around support infill
  468. # TODO: use brim ordering algorithm
  469. push @paths, map Slic3r::ExtrusionPath->new(
  470. polyline => $_->split_at_first_point,
  471. role => EXTR_ROLE_SUPPORTMATERIAL,
  472. height => undef,
  473. flow_spacing => $flow->spacing,
  474. ), map @$_, @$to_infill;
  475. # TODO: use offset2_ex()
  476. $to_infill = offset_ex([ map @$_, @$to_infill ], -$flow->scaled_spacing);
  477. }
  478. foreach my $expolygon (@$to_infill) {
  479. my ($params, @p) = $filler->fill_surface(
  480. Slic3r::Surface->new(expolygon => $expolygon, surface_type => S_TYPE_INTERNAL),
  481. density => $density,
  482. flow_spacing => $flow_spacing,
  483. complete => 1,
  484. );
  485. push @paths, map Slic3r::ExtrusionPath->new(
  486. polyline => Slic3r::Polyline->new(@$_),
  487. role => EXTR_ROLE_SUPPORTMATERIAL,
  488. height => undef,
  489. flow_spacing => $params->{flow_spacing},
  490. ), @p;
  491. }
  492. $layer->support_fills->append(@paths);
  493. }
  494. if (0) {
  495. require "Slic3r/SVG.pm";
  496. Slic3r::SVG::output("islands_" . $z . ".svg",
  497. red_expolygons => union_ex($contact),
  498. green_expolygons => union_ex($interface),
  499. green_polylines => [ map $_->unpack->polyline, @{$layer->support_contact_fills} ],
  500. polylines => [ map $_->unpack->polyline, @{$layer->support_fills} ],
  501. );
  502. }
  503. };
  504. Slic3r::parallelize(
  505. items => [ 0 .. $#{$object->support_layers} ],
  506. thread_cb => sub {
  507. my $q = shift;
  508. while (defined (my $layer_id = $q->dequeue)) {
  509. $process_layer->($layer_id);
  510. }
  511. },
  512. no_threads_cb => sub {
  513. $process_layer->($_) for 0 .. $#{$object->support_layers};
  514. },
  515. );
  516. }
  517. # this method returns the indices of the layers overlapping with the given one
  518. sub overlapping_layers {
  519. my ($self, $i, $support_z) = @_;
  520. my $zmax = $support_z->[$i];
  521. my $zmin = ($i == 0) ? 0 : $support_z->[$i-1];
  522. return grep {
  523. my $zmax2 = $support_z->[$_];
  524. my $zmin2 = ($_ == 0) ? 0 : $support_z->[$_-1];
  525. $zmax > $zmin2 && $zmin < $zmax2;
  526. } 0..$#$support_z;
  527. }
  528. 1;