Print.pm 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. package Slic3r::Print;
  2. use Moo;
  3. use File::Basename qw(basename fileparse);
  4. use File::Spec;
  5. use List::Util qw(max first);
  6. use Math::ConvexHull::MonotoneChain qw(convex_hull);
  7. use Slic3r::ExtrusionPath ':roles';
  8. use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN PI scale unscale move_points nearest_point);
  9. use Slic3r::Geometry::Clipper qw(diff_ex union_ex intersection_ex offset JT_ROUND JT_SQUARE);
  10. use Time::HiRes qw(gettimeofday tv_interval);
  11. has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1);
  12. has 'extra_variables' => (is => 'rw', default => sub {{}});
  13. has 'objects' => (is => 'rw', default => sub {[]});
  14. has 'total_extrusion_length' => (is => 'rw');
  15. has 'processing_time' => (is => 'rw');
  16. has 'extruders' => (is => 'rw', default => sub {[]});
  17. has 'regions' => (is => 'rw', default => sub {[]});
  18. has 'support_material_flow' => (is => 'rw');
  19. has 'first_layer_support_material_flow' => (is => 'rw');
  20. has 'has_support_material' => (is => 'lazy');
  21. # ordered collection of extrusion paths to build skirt loops
  22. has 'skirt' => (
  23. is => 'rw',
  24. #isa => 'ArrayRef[Slic3r::ExtrusionLoop]',
  25. default => sub { [] },
  26. );
  27. # ordered collection of extrusion paths to build a brim
  28. has 'brim' => (
  29. is => 'rw',
  30. #isa => 'ArrayRef[Slic3r::ExtrusionLoop]',
  31. default => sub { [] },
  32. );
  33. sub BUILD {
  34. my $self = shift;
  35. # call this manually because the 'default' coderef doesn't trigger the trigger
  36. $self->_trigger_config;
  37. }
  38. sub _trigger_config {
  39. my $self = shift;
  40. # store config in a handy place
  41. $Slic3r::Config = $self->config;
  42. # legacy with existing config files
  43. $self->config->set('first_layer_height', $self->config->layer_height)
  44. if !$self->config->first_layer_height;
  45. $self->config->set_ifndef('small_perimeter_speed', $self->config->perimeter_speed);
  46. $self->config->set_ifndef('bridge_speed', $self->config->infill_speed);
  47. $self->config->set_ifndef('solid_infill_speed', $self->config->infill_speed);
  48. $self->config->set_ifndef('top_solid_infill_speed', $self->config->solid_infill_speed);
  49. $self->config->set_ifndef('top_solid_layers', $self->config->solid_layers);
  50. $self->config->set_ifndef('bottom_solid_layers', $self->config->solid_layers);
  51. # G-code flavors
  52. $self->config->set('extrusion_axis', 'A') if $self->config->gcode_flavor eq 'mach3';
  53. $self->config->set('extrusion_axis', '') if $self->config->gcode_flavor eq 'no-extrusion';
  54. }
  55. sub _build_has_support_material {
  56. my $self = shift;
  57. return $self->config->support_material
  58. || $self->config->raft_layers > 0
  59. || $self->config->support_material_enforce_layers > 0;
  60. }
  61. sub add_model {
  62. my $self = shift;
  63. my ($model) = @_;
  64. # append/merge materials and preserve a mapping between the original material ID
  65. # and our numeric material index
  66. my %materials = ();
  67. {
  68. my @material_ids = sort keys %{$model->materials};
  69. @material_ids = (0) if !@material_ids;
  70. for (my $i = $self->regions_count; $i < @material_ids; $i++) {
  71. push @{$self->regions}, Slic3r::Print::Region->new;
  72. $materials{$material_ids[$i]} = $#{$self->regions};
  73. }
  74. }
  75. foreach my $object (@{ $model->objects }) {
  76. my @meshes = (); # by region_id
  77. foreach my $volume (@{$object->volumes}) {
  78. # should the object contain multiple volumes of the same material, merge them
  79. my $region_id = defined $volume->material_id ? $materials{$volume->material_id} : 0;
  80. my $mesh = $volume->mesh->clone;
  81. $meshes[$region_id] = $meshes[$region_id]
  82. ? Slic3r::TriangleMesh->merge($meshes[$region_id], $mesh)
  83. : $mesh;
  84. }
  85. foreach my $mesh (@meshes) {
  86. next unless $mesh;
  87. $mesh->check_manifoldness;
  88. if ($object->instances) {
  89. # we ignore the per-instance rotation currently and only
  90. # consider the first one
  91. $mesh->rotate($object->instances->[0]->rotation);
  92. }
  93. $mesh->rotate($Slic3r::Config->rotate);
  94. $mesh->scale($Slic3r::Config->scale / &Slic3r::SCALING_FACTOR);
  95. }
  96. my $complete_mesh = Slic3r::TriangleMesh->merge(grep defined $_, @meshes);
  97. # initialize print object
  98. my $print_object = Slic3r::Print::Object->new(
  99. print => $self,
  100. meshes => [ @meshes ],
  101. size => [ $complete_mesh->size ],
  102. input_file => $object->input_file
  103. );
  104. push @{$self->objects}, $print_object;
  105. # align object to origin
  106. {
  107. my @extents = $complete_mesh->extents;
  108. foreach my $mesh (grep defined $_, @meshes) {
  109. $mesh->move(map -$extents[$_][MIN], X,Y,Z);
  110. }
  111. }
  112. if ($object->instances) {
  113. # replace the default [0,0] instance with the custom ones
  114. @{$print_object->copies} = map [ scale $_->offset->[X], scale $_->offset->[Y] ], @{$object->instances};
  115. }
  116. }
  117. }
  118. sub validate {
  119. my $self = shift;
  120. if ($Slic3r::Config->complete_objects) {
  121. # check horizontal clearance
  122. {
  123. my @a = ();
  124. for my $obj_idx (0 .. $#{$self->objects}) {
  125. my $clearance;
  126. {
  127. my @points = map [ @$_[X,Y] ], map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes};
  128. my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
  129. $clearance = +($convex_hull->offset(scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND))[0];
  130. }
  131. for my $copy (@{$self->objects->[$obj_idx]->copies}) {
  132. my $copy_clearance = $clearance->clone;
  133. $copy_clearance->translate(@$copy);
  134. if (@{ intersection_ex(\@a, [$copy_clearance]) }) {
  135. die "Some objects are too close; your extruder will collide with them.\n";
  136. }
  137. @a = map @$_, @{union_ex([ @a, $copy_clearance ])};
  138. }
  139. }
  140. }
  141. # check vertical clearance
  142. {
  143. my @obj_copies = $self->object_copies;
  144. pop @obj_copies; # ignore the last copy: its height doesn't matter
  145. my $scaled_clearance = scale $Slic3r::Config->extruder_clearance_height;
  146. if (grep { +($_->size)[Z] > $scaled_clearance } map @{$self->objects->[$_->[0]]->meshes}, @obj_copies) {
  147. die "Some objects are too tall and cannot be printed without extruder collisions.\n";
  148. }
  149. }
  150. }
  151. }
  152. sub init_extruders {
  153. my $self = shift;
  154. # map regions to extruders (ghetto mapping for now)
  155. my %extruder_mapping = map { $_ => $_ } 0..$#{$self->regions};
  156. # initialize all extruder(s) we need
  157. my @used_extruders = (
  158. 0,
  159. (map $self->config->get("${_}_extruder")-1, qw(perimeter infill support_material)),
  160. (values %extruder_mapping),
  161. );
  162. for my $extruder_id (keys %{{ map {$_ => 1} @used_extruders }}) {
  163. $self->extruders->[$extruder_id] = Slic3r::Extruder->new(
  164. id => $extruder_id,
  165. map { $_ => $self->config->get($_)->[$extruder_id] // $self->config->get($_)->[0] } #/
  166. @{&Slic3r::Extruder::OPTIONS}
  167. );
  168. }
  169. # calculate default flows
  170. $Slic3r::flow = $self->extruders->[0]->make_flow(
  171. width => $self->config->extrusion_width,
  172. );
  173. $Slic3r::first_layer_flow = $self->extruders->[0]->make_flow(
  174. layer_height => $self->config->get_value('first_layer_height'),
  175. width => $self->config->first_layer_extrusion_width,
  176. );
  177. # calculate regions' flows
  178. for my $region_id (0 .. $#{$self->regions}) {
  179. my $region = $self->regions->[$region_id];
  180. # per-role extruders and flows
  181. for (qw(perimeter infill)) {
  182. $region->extruders->{$_} = ($self->regions_count > 1)
  183. ? $self->extruders->[$extruder_mapping{$region_id}]
  184. : $self->extruders->[$self->config->get("${_}_extruder")-1];
  185. $region->flows->{$_} = $region->extruders->{$_}->make_flow(
  186. width => $self->config->get("${_}_extrusion_width") || $self->config->extrusion_width,
  187. );
  188. $region->first_layer_flows->{$_} = $region->extruders->{$_}->make_flow(
  189. layer_height => $self->config->get_value('first_layer_height'),
  190. width => $self->config->first_layer_extrusion_width,
  191. );
  192. }
  193. }
  194. # calculate support material flow
  195. if ($self->has_support_material) {
  196. my $extruder = $self->extruders->[$self->config->support_material_extruder-1];
  197. $self->support_material_flow($extruder->make_flow(
  198. width => $self->config->support_material_extrusion_width || $self->config->extrusion_width,
  199. ));
  200. $self->first_layer_support_material_flow($extruder->make_flow(
  201. layer_height => $self->config->get_value('first_layer_height'),
  202. width => $self->config->first_layer_extrusion_width,
  203. ));
  204. }
  205. Slic3r::debugf "Default flow width = %s (spacing = %s)\n",
  206. $Slic3r::flow->width, $Slic3r::flow->spacing;
  207. }
  208. sub object_copies {
  209. my $self = shift;
  210. my @oc = ();
  211. for my $obj_idx (0 .. $#{$self->objects}) {
  212. push @oc, map [ $obj_idx, $_ ], @{$self->objects->[$obj_idx]->copies};
  213. }
  214. return @oc;
  215. }
  216. sub layer_count {
  217. my $self = shift;
  218. return max(map { scalar @{$_->layers} } @{$self->objects});
  219. }
  220. sub regions_count {
  221. my $self = shift;
  222. return scalar @{$self->regions};
  223. }
  224. sub duplicate {
  225. my $self = shift;
  226. if ($Slic3r::Config->duplicate_grid->[X] > 1 || $Slic3r::Config->duplicate_grid->[Y] > 1) {
  227. if (@{$self->objects} > 1) {
  228. die "Grid duplication is not supported with multiple objects\n";
  229. }
  230. my $object = $self->objects->[0];
  231. # generate offsets for copies
  232. my $dist = scale $Slic3r::Config->duplicate_distance;
  233. @{$self->objects->[0]->copies} = ();
  234. for my $x_copy (1..$Slic3r::Config->duplicate_grid->[X]) {
  235. for my $y_copy (1..$Slic3r::Config->duplicate_grid->[Y]) {
  236. push @{$self->objects->[0]->copies}, [
  237. ($object->size->[X] + $dist) * ($x_copy-1),
  238. ($object->size->[Y] + $dist) * ($y_copy-1),
  239. ];
  240. }
  241. }
  242. } elsif ($Slic3r::Config->duplicate > 1) {
  243. foreach my $object (@{$self->objects}) {
  244. @{$object->copies} = map [0,0], 1..$Slic3r::Config->duplicate;
  245. }
  246. $self->arrange_objects;
  247. }
  248. }
  249. sub arrange_objects {
  250. my $self = shift;
  251. my $total_parts = scalar map @{$_->copies}, @{$self->objects};
  252. my $partx = max(map $_->size->[X], @{$self->objects});
  253. my $party = max(map $_->size->[Y], @{$self->objects});
  254. my @positions = Slic3r::Geometry::arrange
  255. ($total_parts, $partx, $party, (map scale $_, @{$Slic3r::Config->bed_size}), scale $Slic3r::Config->min_object_distance, $self->config);
  256. @{$_->copies} = splice @positions, 0, scalar @{$_->copies} for @{$self->objects};
  257. }
  258. sub bounding_box {
  259. my $self = shift;
  260. my @points = ();
  261. foreach my $obj_idx (0 .. $#{$self->objects}) {
  262. my $object = $self->objects->[$obj_idx];
  263. foreach my $copy (@{$self->objects->[$obj_idx]->copies}) {
  264. push @points,
  265. [ $copy->[X], $copy->[Y] ],
  266. [ $copy->[X] + $object->size->[X], $copy->[Y] ],
  267. [ $copy->[X] + $object->size->[X], $copy->[Y] + $object->size->[Y] ],
  268. [ $copy->[X], $copy->[Y] + $object->size->[Y] ];
  269. }
  270. }
  271. return Slic3r::Geometry::bounding_box(\@points);
  272. }
  273. sub size {
  274. my $self = shift;
  275. my @bb = $self->bounding_box;
  276. return [ $bb[X2] - $bb[X1], $bb[Y2] - $bb[Y1] ];
  277. }
  278. sub export_gcode {
  279. my $self = shift;
  280. my %params = @_;
  281. $self->init_extruders;
  282. my $status_cb = $params{status_cb} || sub {};
  283. my $t0 = [gettimeofday];
  284. # skein the STL into layers
  285. # each layer has surfaces with holes
  286. $status_cb->(10, "Processing triangulated mesh");
  287. $_->slice(keep_meshes => $params{keep_meshes}) for @{$self->objects};
  288. # make perimeters
  289. # this will add a set of extrusion loops to each layer
  290. # as well as generate infill boundaries
  291. $status_cb->(20, "Generating perimeters");
  292. $_->make_perimeters for @{$self->objects};
  293. # simplify slices (both layer and region slices),
  294. # we only need the max resolution for perimeters
  295. foreach my $layer (map @{$_->layers}, @{$self->objects}) {
  296. $_->simplify(&Slic3r::SCALED_RESOLUTION)
  297. for @{$layer->slices}, (map $_->expolygon, map @{$_->slices}, @{$layer->regions});
  298. }
  299. # this will transform $layer->fill_surfaces from expolygon
  300. # to typed top/bottom/internal surfaces;
  301. $status_cb->(30, "Detecting solid surfaces");
  302. $_->detect_surfaces_type for @{$self->objects};
  303. # decide what surfaces are to be filled
  304. $status_cb->(35, "Preparing infill surfaces");
  305. $_->prepare_fill_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
  306. # this will detect bridges and reverse bridges
  307. # and rearrange top/bottom/internal surfaces
  308. $status_cb->(45, "Detect bridges");
  309. $_->process_bridges for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
  310. # detect which fill surfaces are near external layers
  311. # they will be split in internal and internal-solid surfaces
  312. $status_cb->(60, "Generating horizontal shells");
  313. $_->discover_horizontal_shells for @{$self->objects};
  314. # combine fill surfaces to honor the "infill every N layers" option
  315. $status_cb->(70, "Combining infill");
  316. $_->combine_infill for @{$self->objects};
  317. # this will generate extrusion paths for each layer
  318. $status_cb->(80, "Infilling layers");
  319. {
  320. my $fill_maker = Slic3r::Fill->new('print' => $self);
  321. Slic3r::parallelize(
  322. items => sub {
  323. my @items = (); # [obj_idx, layer_id]
  324. for my $obj_idx (0 .. $#{$self->objects}) {
  325. for my $region_id (0 .. ($self->regions_count-1)) {
  326. push @items, map [$obj_idx, $_, $region_id], 0..($self->objects->[$obj_idx]->layer_count-1);
  327. }
  328. }
  329. @items;
  330. },
  331. thread_cb => sub {
  332. my $q = shift;
  333. $Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
  334. my $fills = {};
  335. while (defined (my $obj_layer = $q->dequeue)) {
  336. my ($obj_idx, $layer_id, $region_id) = @$obj_layer;
  337. $fills->{$obj_idx} ||= {};
  338. $fills->{$obj_idx}{$layer_id} ||= {};
  339. $fills->{$obj_idx}{$layer_id}{$region_id} = [
  340. $fill_maker->make_fill($self->objects->[$obj_idx]->layers->[$layer_id]->regions->[$region_id]),
  341. ];
  342. }
  343. return $fills;
  344. },
  345. collect_cb => sub {
  346. my $fills = shift;
  347. foreach my $obj_idx (keys %$fills) {
  348. my $object = $self->objects->[$obj_idx];
  349. foreach my $layer_id (keys %{$fills->{$obj_idx}}) {
  350. my $layer = $object->layers->[$layer_id];
  351. foreach my $region_id (keys %{$fills->{$obj_idx}{$layer_id}}) {
  352. $layer->regions->[$region_id]->fills($fills->{$obj_idx}{$layer_id}{$region_id});
  353. }
  354. }
  355. }
  356. },
  357. no_threads_cb => sub {
  358. foreach my $layerm (map @{$_->regions}, map @{$_->layers}, @{$self->objects}) {
  359. $layerm->fills([ $fill_maker->make_fill($layerm) ]);
  360. }
  361. },
  362. );
  363. }
  364. # generate support material
  365. if ($self->has_support_material) {
  366. $status_cb->(85, "Generating support material");
  367. $_->generate_support_material for @{$self->objects};
  368. }
  369. # free memory (note that support material needs fill_surfaces)
  370. $_->fill_surfaces(undef) for map @{$_->regions}, map @{$_->layers}, @{$self->objects};
  371. # make skirt
  372. $status_cb->(88, "Generating skirt");
  373. $self->make_skirt;
  374. $self->make_brim; # must come after make_skirt
  375. # output everything to a G-code file
  376. my $output_file = $self->expanded_output_filepath($params{output_file});
  377. $status_cb->(90, "Exporting G-code" . ($output_file ? " to $output_file" : ""));
  378. $self->write_gcode($params{output_fh} || $output_file);
  379. # run post-processing scripts
  380. if (@{$Slic3r::Config->post_process}) {
  381. $status_cb->(95, "Running post-processing scripts");
  382. $Slic3r::Config->setenv;
  383. for (@{$Slic3r::Config->post_process}) {
  384. Slic3r::debugf " '%s' '%s'\n", $_, $output_file;
  385. system($_, $output_file);
  386. }
  387. }
  388. # output some statistics
  389. unless ($params{quiet}) {
  390. $self->processing_time(tv_interval($t0));
  391. printf "Done. Process took %d minutes and %.3f seconds\n",
  392. int($self->processing_time/60),
  393. $self->processing_time - int($self->processing_time/60)*60;
  394. # TODO: more statistics!
  395. printf "Filament required: %.1fmm (%.1fcm3)\n",
  396. $self->total_extrusion_length, $self->total_extrusion_volume;
  397. }
  398. }
  399. sub export_svg {
  400. my $self = shift;
  401. my %params = @_;
  402. # this shouldn't be needed, but we're currently relying on ->make_surfaces() which
  403. # calls ->perimeter_flow
  404. $self->init_extruders;
  405. $_->slice(keep_meshes => $params{keep_meshes}) for @{$self->objects};
  406. $self->arrange_objects;
  407. my $output_file = $self->expanded_output_filepath($params{output_file});
  408. $output_file =~ s/\.gcode$/.svg/i;
  409. Slic3r::open(\my $fh, ">", $output_file) or die "Failed to open $output_file for writing\n";
  410. print "Exporting to $output_file...";
  411. my $print_size = $self->size;
  412. print $fh sprintf <<"EOF", unscale($print_size->[X]), unscale($print_size->[Y]);
  413. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  414. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
  415. <svg width="%s" height="%s" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:slic3r="http://slic3r.org/namespaces/slic3r">
  416. <!--
  417. Generated using Slic3r $Slic3r::VERSION
  418. http://slic3r.org/
  419. -->
  420. EOF
  421. my $print_polygon = sub {
  422. my ($polygon, $type) = @_;
  423. printf $fh qq{ <polygon slic3r:type="%s" points="%s" style="fill: %s" />\n},
  424. $type, (join ' ', map { join ',', map unscale $_, @$_ } @$polygon),
  425. ($type eq 'contour' ? 'white' : 'black');
  426. };
  427. my @previous_layer_slices = ();
  428. for my $layer_id (0..$self->layer_count-1) {
  429. my @layers = map $_->layers->[$layer_id], @{$self->objects};
  430. printf $fh qq{ <g id="layer%d" slic3r:z="%s">\n}, $layer_id, unscale +(grep defined $_, @layers)[0]->slice_z;
  431. my @current_layer_slices = ();
  432. for my $obj_idx (0 .. $#{$self->objects}) {
  433. my $layer = $self->objects->[$obj_idx]->layers->[$layer_id] or next;
  434. # sort slices so that the outermost ones come first
  435. my @slices = sort { $a->contour->encloses_point($b->contour->[0]) ? 0 : 1 } @{$layer->slices};
  436. foreach my $copy (@{$self->objects->[$obj_idx]->copies}) {
  437. foreach my $slice (@slices) {
  438. my $expolygon = $slice->clone;
  439. $expolygon->translate(@$copy);
  440. $print_polygon->($expolygon->contour, 'contour');
  441. $print_polygon->($_, 'hole') for $expolygon->holes;
  442. push @current_layer_slices, $expolygon;
  443. }
  444. }
  445. }
  446. # generate support material
  447. if ($self->has_support_material && $layer_id > 0) {
  448. my (@supported_slices, @unsupported_slices) = ();
  449. foreach my $expolygon (@current_layer_slices) {
  450. my $intersection = intersection_ex(
  451. [ map @$_, @previous_layer_slices ],
  452. $expolygon,
  453. );
  454. @$intersection
  455. ? push @supported_slices, $expolygon
  456. : push @unsupported_slices, $expolygon;
  457. }
  458. my @supported_points = map @$_, @$_, @supported_slices;
  459. foreach my $expolygon (@unsupported_slices) {
  460. # look for the nearest point to this island among all
  461. # supported points
  462. my $support_point = nearest_point($expolygon->contour->[0], \@supported_points)
  463. or next;
  464. my $anchor_point = nearest_point($support_point, $expolygon->contour);
  465. printf $fh qq{ <line x1="%s" y1="%s" x2="%s" y2="%s" style="stroke-width: 2; stroke: white" />\n},
  466. map @$_, $support_point, $anchor_point;
  467. }
  468. }
  469. print $fh qq{ </g>\n};
  470. @previous_layer_slices = @current_layer_slices;
  471. }
  472. print $fh "</svg>\n";
  473. close $fh;
  474. print "Done.\n";
  475. }
  476. sub make_skirt {
  477. my $self = shift;
  478. return unless $Slic3r::Config->skirts > 0;
  479. # collect points from all layers contained in skirt height
  480. my @points = ();
  481. foreach my $obj_idx (0 .. $#{$self->objects}) {
  482. my $skirt_height = $Slic3r::Config->skirt_height;
  483. $skirt_height = $self->objects->[$obj_idx]->layer_count if $skirt_height > $self->objects->[$obj_idx]->layer_count;
  484. my @layers = map $self->objects->[$obj_idx]->layers->[$_], 0..($skirt_height-1);
  485. my @layer_points = (
  486. (map @$_, map @$_, map @{$_->slices}, @layers),
  487. (map @$_, map @{$_->thin_walls}, map @{$_->regions}, @layers),
  488. (map @{$_->unpack->polyline}, map @{$_->support_fills->paths}, grep $_->support_fills, @layers),
  489. );
  490. push @points, map move_points($_, @layer_points), @{$self->objects->[$obj_idx]->copies};
  491. }
  492. return if @points < 3; # at least three points required for a convex hull
  493. # find out convex hull
  494. my $convex_hull = convex_hull(\@points);
  495. my @extruded_length = (); # for each extruder
  496. my $spacing = $Slic3r::first_layer_flow->spacing;
  497. my $first_layer_height = $Slic3r::Config->get_value('first_layer_height');
  498. my @extruders_e_per_mm = ();
  499. my $extruder_idx = 0;
  500. # draw outlines from outside to inside
  501. # loop while we have less skirts than required or any extruder hasn't reached the min length if any
  502. my $distance = scale $Slic3r::Config->skirt_distance;
  503. for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) {
  504. $distance += scale $spacing;
  505. my ($loop) = Slic3r::Geometry::Clipper::offset([$convex_hull], $distance, 0.0001, JT_ROUND);
  506. push @{$self->skirt}, Slic3r::ExtrusionLoop->pack(
  507. polygon => Slic3r::Polygon->new(@$loop),
  508. role => EXTR_ROLE_SKIRT,
  509. flow_spacing => $spacing,
  510. );
  511. if ($Slic3r::Config->min_skirt_length > 0) {
  512. bless $loop, 'Slic3r::Polygon';
  513. $extruded_length[$extruder_idx] ||= 0;
  514. $extruders_e_per_mm[$extruder_idx] ||= $self->extruders->[$extruder_idx]->e_per_mm($spacing, $first_layer_height);
  515. $extruded_length[$extruder_idx] += unscale $loop->length * $extruders_e_per_mm[$extruder_idx];
  516. $i++ if defined first { ($extruded_length[$_] // 0) < $Slic3r::Config->min_skirt_length } 0 .. $#{$self->extruders};
  517. if ($extruded_length[$extruder_idx] >= $Slic3r::Config->min_skirt_length) {
  518. if ($extruder_idx < $#{$self->extruders}) {
  519. $extruder_idx++;
  520. next;
  521. }
  522. }
  523. }
  524. }
  525. @{$self->skirt} = reverse @{$self->skirt};
  526. }
  527. sub make_brim {
  528. my $self = shift;
  529. return unless $Slic3r::Config->brim_width > 0;
  530. my $grow_distance = $Slic3r::first_layer_flow->scaled_width / 2;
  531. my @islands = (); # array of polygons
  532. foreach my $obj_idx (0 .. $#{$self->objects}) {
  533. my $layer0 = $self->objects->[$obj_idx]->layers->[0];
  534. my @object_islands = (
  535. (map $_->contour, @{$layer0->slices}),
  536. (map { $_->isa('Slic3r::Polygon') ? $_ : $_->grow($grow_distance) } map @{$_->thin_walls}, @{$layer0->regions}),
  537. (map $_->unpack->polyline->grow($grow_distance), map @{$_->support_fills->paths}, grep $_->support_fills, $layer0),
  538. );
  539. foreach my $copy (@{$self->objects->[$obj_idx]->copies}) {
  540. push @islands, map $_->clone->translate(@$copy), @object_islands;
  541. }
  542. }
  543. # if brim touches skirt, make it around skirt too
  544. if ($Slic3r::Config->skirt_distance + (($Slic3r::Config->skirts - 1) * $Slic3r::first_layer_flow->spacing) <= $Slic3r::Config->brim_width) {
  545. push @islands, map $_->unpack->split_at_first_point->polyline->grow($grow_distance), @{$self->skirt};
  546. }
  547. my $num_loops = sprintf "%.0f", $Slic3r::Config->brim_width / $Slic3r::first_layer_flow->width;
  548. for my $i (reverse 1 .. $num_loops) {
  549. # JT_SQUARE ensures no vertex is outside the given offset distance
  550. push @{$self->brim}, Slic3r::ExtrusionLoop->pack(
  551. polygon => Slic3r::Polygon->new($_),
  552. role => EXTR_ROLE_SKIRT,
  553. flow_spacing => $Slic3r::first_layer_flow->spacing,
  554. ) for Slic3r::Geometry::Clipper::offset(\@islands, $i * $Slic3r::first_layer_flow->scaled_spacing, undef, JT_SQUARE);
  555. # TODO: we need the offset inwards/offset outwards logic to avoid overlapping extrusions
  556. }
  557. }
  558. sub write_gcode {
  559. my $self = shift;
  560. my ($file) = @_;
  561. # open output gcode file if we weren't supplied a file-handle
  562. my $fh;
  563. if (ref $file eq 'IO::Scalar') {
  564. $fh = $file;
  565. } else {
  566. Slic3r::open(\$fh, ">", $file)
  567. or die "Failed to open $file for writing\n";
  568. }
  569. # write some information
  570. my @lt = localtime;
  571. printf $fh "; generated by Slic3r $Slic3r::VERSION on %04d-%02d-%02d at %02d:%02d:%02d\n\n",
  572. $lt[5] + 1900, $lt[4]+1, $lt[3], $lt[2], $lt[1], $lt[0];
  573. print $fh "; $_\n" foreach split /\R/, $Slic3r::Config->notes;
  574. print $fh "\n" if $Slic3r::Config->notes;
  575. for (qw(layer_height perimeters top_solid_layers bottom_solid_layers fill_density perimeter_speed infill_speed travel_speed scale)) {
  576. printf $fh "; %s = %s\n", $_, $Slic3r::Config->$_;
  577. }
  578. for (qw(nozzle_diameter filament_diameter extrusion_multiplier)) {
  579. printf $fh "; %s = %s\n", $_, $Slic3r::Config->$_->[0];
  580. }
  581. printf $fh "; perimeters extrusion width = %.2fmm\n", $self->regions->[0]->flows->{perimeter}->width;
  582. printf $fh "; infill extrusion width = %.2fmm\n", $self->regions->[0]->flows->{infill}->width;
  583. printf $fh "; support material extrusion width = %.2fmm\n", $self->support_material_flow->width
  584. if $self->support_material_flow;
  585. printf $fh "; first layer extrusion width = %.2fmm\n", $Slic3r::first_layer_flow->width
  586. if $Slic3r::first_layer_flow;
  587. print $fh "\n";
  588. # set up our extruder object
  589. my $gcodegen = Slic3r::GCode->new(
  590. multiple_extruders => (@{$self->extruders} > 1),
  591. layer_count => $self->layer_count,
  592. );
  593. my $min_print_speed = 60 * $Slic3r::Config->min_print_speed;
  594. my $dec = $gcodegen->dec;
  595. print $fh $gcodegen->set_fan(0, 1) if $Slic3r::Config->cooling && $Slic3r::Config->disable_fan_first_layers;
  596. # write start commands to file
  597. printf $fh $gcodegen->set_bed_temperature($Slic3r::Config->first_layer_bed_temperature, 1),
  598. if $Slic3r::Config->first_layer_bed_temperature && $Slic3r::Config->start_gcode !~ /M190/i;
  599. my $print_first_layer_temperature = sub {
  600. for my $t (grep $self->extruders->[$_], 0 .. $#{$Slic3r::Config->first_layer_temperature}) {
  601. printf $fh $gcodegen->set_temperature($self->extruders->[$t]->first_layer_temperature, 0, $t)
  602. if $self->extruders->[$t]->first_layer_temperature;
  603. }
  604. };
  605. $print_first_layer_temperature->();
  606. printf $fh "%s\n", $Slic3r::Config->replace_options($Slic3r::Config->start_gcode);
  607. for my $t (grep $self->extruders->[$_], 0 .. $#{$Slic3r::Config->first_layer_temperature}) {
  608. printf $fh $gcodegen->set_temperature($self->extruders->[$t]->first_layer_temperature, 1, $t)
  609. if $self->extruders->[$t]->first_layer_temperature && $Slic3r::Config->start_gcode !~ /M109/i;
  610. }
  611. print $fh "G90 ; use absolute coordinates\n";
  612. print $fh "G21 ; set units to millimeters\n";
  613. if ($Slic3r::Config->gcode_flavor =~ /^(?:reprap|teacup)$/) {
  614. printf $fh $gcodegen->reset_e;
  615. if ($Slic3r::Config->gcode_flavor =~ /^(?:reprap|makerbot|sailfish)$/) {
  616. if ($Slic3r::Config->use_relative_e_distances) {
  617. print $fh "M83 ; use relative distances for extrusion\n";
  618. } else {
  619. print $fh "M82 ; use absolute distances for extrusion\n";
  620. }
  621. }
  622. }
  623. # calculate X,Y shift to center print around specified origin
  624. my @print_bb = $self->bounding_box;
  625. my @shift = (
  626. $Slic3r::Config->print_center->[X] - (unscale ($print_bb[X2] - $print_bb[X1]) / 2) - unscale $print_bb[X1],
  627. $Slic3r::Config->print_center->[Y] - (unscale ($print_bb[Y2] - $print_bb[Y1]) / 2) - unscale $print_bb[Y1],
  628. );
  629. # initialize a motion planner for object-to-object travel moves
  630. if ($Slic3r::Config->avoid_crossing_perimeters) {
  631. my $distance_from_objects = 1;
  632. # compute the offsetted convex hull for each object and repeat it for each copy.
  633. my @islands = ();
  634. foreach my $obj_idx (0 .. $#{$self->objects}) {
  635. my @island = Slic3r::ExPolygon->new(convex_hull([
  636. map @{$_->contour}, map @{$_->slices}, @{$self->objects->[$obj_idx]->layers},
  637. ]))->translate(scale $shift[X], scale $shift[Y])->offset_ex(scale $distance_from_objects, 1, JT_SQUARE);
  638. foreach my $copy (@{ $self->objects->[$obj_idx]->copies }) {
  639. push @islands, map $_->clone->translate(@$copy), @island;
  640. }
  641. }
  642. $gcodegen->external_mp(Slic3r::GCode::MotionPlanner->new(
  643. islands => union_ex([ map @$_, @islands ]),
  644. no_internal => 1,
  645. ));
  646. }
  647. # prepare the logic to print one layer
  648. my $skirt_done = 0; # count of skirt layers done
  649. my $brim_done = 0;
  650. my $last_obj_copy = "";
  651. my $extrude_layer = sub {
  652. my ($layer_id, $object_copies) = @_;
  653. my $gcode = "";
  654. if ($layer_id == 1) {
  655. for my $t (grep $self->extruders->[$_], 0 .. $#{$Slic3r::Config->temperature}) {
  656. $gcode .= $gcodegen->set_temperature($self->extruders->[$t]->temperature, 0, $t)
  657. if $self->extruders->[$t]->temperature && $self->extruders->[$t]->temperature != $self->extruders->[$t]->first_layer_temperature;
  658. }
  659. $gcode .= $gcodegen->set_bed_temperature($Slic3r::Config->bed_temperature)
  660. if $Slic3r::Config->bed_temperature && $Slic3r::Config->bed_temperature != $Slic3r::Config->first_layer_bed_temperature;
  661. }
  662. # set new layer, but don't move Z as support material contact areas may need an intermediate one
  663. $gcode .= $gcodegen->change_layer($self->objects->[$object_copies->[0][0]]->layers->[$layer_id]);
  664. $gcodegen->elapsed_time(0);
  665. # prepare callback to call as soon as a Z command is generated
  666. $gcodegen->move_z_callback(sub {
  667. $gcodegen->move_z_callback(undef); # circular ref or not?
  668. return "" if !$Slic3r::Config->layer_gcode;
  669. return $Slic3r::Config->replace_options($Slic3r::Config->layer_gcode) . "\n";
  670. });
  671. # extrude skirt
  672. if ($skirt_done < $Slic3r::Config->skirt_height) {
  673. $gcodegen->set_shift(@shift);
  674. $gcode .= $gcodegen->set_extruder($self->extruders->[0]); # move_z requires extruder
  675. $gcode .= $gcodegen->move_z($gcodegen->layer->print_z);
  676. # skip skirt if we have a large brim
  677. if ($layer_id < $Slic3r::Config->skirt_height) {
  678. # distribute skirt loops across all extruders
  679. for my $i (0 .. $#{$self->skirt}) {
  680. # when printing layers > 0 ignore 'min_skirt_length' and
  681. # just use the 'skirts' setting; also just use the current extruder
  682. last if ($layer_id > 0) && ($i >= $Slic3r::Config->skirts);
  683. $gcode .= $gcodegen->set_extruder($self->extruders->[ ($i/@{$self->extruders}) % @{$self->extruders} ])
  684. if $layer_id == 0;
  685. $gcode .= $gcodegen->extrude_loop($self->skirt->[$i], 'skirt');
  686. }
  687. }
  688. $skirt_done++;
  689. $gcodegen->straight_once(1);
  690. }
  691. # extrude brim
  692. if ($layer_id == 0 && !$brim_done) {
  693. $gcode .= $gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]); # move_z requires extruder
  694. $gcode .= $gcodegen->move_z($gcodegen->layer->print_z);
  695. $gcodegen->set_shift(@shift);
  696. $gcode .= $gcodegen->extrude_loop($_, 'brim') for @{$self->brim};
  697. $brim_done = 1;
  698. $gcodegen->straight_once(1);
  699. }
  700. for my $obj_copy (@$object_copies) {
  701. my ($obj_idx, $copy) = @$obj_copy;
  702. $gcodegen->new_object(1) if $last_obj_copy && $last_obj_copy ne "${obj_idx}_${copy}";
  703. $last_obj_copy = "${obj_idx}_${copy}";
  704. my $layer = $self->objects->[$obj_idx]->layers->[$layer_id];
  705. $gcodegen->set_shift(map $shift[$_] + unscale $copy->[$_], X,Y);
  706. # extrude support material before other things because it might use a lower Z
  707. # and also because we avoid travelling on other things when printing it
  708. if ($self->has_support_material) {
  709. $gcode .= $gcodegen->move_z($layer->support_material_contact_z)
  710. if ($layer->support_contact_fills && @{ $layer->support_contact_fills->paths });
  711. $gcode .= $gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]);
  712. if ($layer->support_contact_fills) {
  713. $gcode .= $gcodegen->extrude_path($_, 'support material contact area')
  714. for $layer->support_contact_fills->shortest_path($gcodegen->last_pos);
  715. }
  716. $gcode .= $gcodegen->move_z($layer->print_z);
  717. if ($layer->support_fills) {
  718. $gcode .= $gcodegen->extrude_path($_, 'support material')
  719. for $layer->support_fills->shortest_path($gcodegen->last_pos);
  720. }
  721. }
  722. # set actual Z - this will force a retraction
  723. $gcode .= $gcodegen->move_z($layer->print_z);
  724. foreach my $region_id (0 .. ($self->regions_count-1)) {
  725. my $layerm = $layer->regions->[$region_id];
  726. my $region = $self->regions->[$region_id];
  727. # extrude perimeters
  728. if (@{ $layerm->perimeters }) {
  729. $gcode .= $gcodegen->set_extruder($region->extruders->{perimeter});
  730. $gcode .= $gcodegen->set_acceleration($Slic3r::Config->perimeter_acceleration);
  731. $gcode .= $gcodegen->extrude($_, 'perimeter') for @{ $layerm->perimeters };
  732. $gcode .= $gcodegen->set_acceleration($Slic3r::Config->default_acceleration)
  733. if $Slic3r::Config->perimeter_acceleration;
  734. }
  735. # extrude fills
  736. if (@{ $layerm->fills }) {
  737. $gcode .= $gcodegen->set_extruder($region->extruders->{infill});
  738. $gcode .= $gcodegen->set_acceleration($Slic3r::Config->infill_acceleration);
  739. for my $fill (@{ $layerm->fills }) {
  740. if ($fill->isa('Slic3r::ExtrusionPath::Collection')) {
  741. $gcode .= $gcodegen->extrude($_, 'fill')
  742. for $fill->shortest_path($gcodegen->last_pos);
  743. } else {
  744. $gcode .= $gcodegen->extrude($fill, 'fill') ;
  745. }
  746. }
  747. $gcode .= $gcodegen->set_acceleration($Slic3r::Config->default_acceleration)
  748. if $Slic3r::Config->infill_acceleration;
  749. }
  750. }
  751. }
  752. return if !$gcode;
  753. my $fan_speed = $Slic3r::Config->fan_always_on ? $Slic3r::Config->min_fan_speed : 0;
  754. my $speed_factor = 1;
  755. if ($Slic3r::Config->cooling) {
  756. my $layer_time = $gcodegen->elapsed_time;
  757. Slic3r::debugf "Layer %d estimated printing time: %d seconds\n", $layer_id, $layer_time;
  758. if ($layer_time < $Slic3r::Config->slowdown_below_layer_time) {
  759. $fan_speed = $Slic3r::Config->max_fan_speed;
  760. $speed_factor = $layer_time / $Slic3r::Config->slowdown_below_layer_time;
  761. } elsif ($layer_time < $Slic3r::Config->fan_below_layer_time) {
  762. $fan_speed = $Slic3r::Config->max_fan_speed - ($Slic3r::Config->max_fan_speed - $Slic3r::Config->min_fan_speed)
  763. * ($layer_time - $Slic3r::Config->slowdown_below_layer_time)
  764. / ($Slic3r::Config->fan_below_layer_time - $Slic3r::Config->slowdown_below_layer_time); #/
  765. }
  766. Slic3r::debugf " fan = %d%%, speed = %d%%\n", $fan_speed, $speed_factor * 100;
  767. if ($speed_factor < 1) {
  768. $gcode =~ s/^(?=.*? [XY])(?=.*? E)(?<!;_BRIDGE_FAN_START\n)(G1 .*?F)(\d+(?:\.\d+)?)/
  769. my $new_speed = $2 * $speed_factor;
  770. $1 . sprintf("%.${dec}f", $new_speed < $min_print_speed ? $min_print_speed : $new_speed)
  771. /gexm;
  772. }
  773. $fan_speed = 0 if $layer_id < $Slic3r::Config->disable_fan_first_layers;
  774. }
  775. $gcode = $gcodegen->set_fan($fan_speed) . $gcode;
  776. # bridge fan speed
  777. if (!$Slic3r::Config->cooling || $Slic3r::Config->bridge_fan_speed == 0 || $layer_id < $Slic3r::Config->disable_fan_first_layers) {
  778. $gcode =~ s/^;_BRIDGE_FAN_(?:START|END)\n//gm;
  779. } else {
  780. $gcode =~ s/^;_BRIDGE_FAN_START\n/ $gcodegen->set_fan($Slic3r::Config->bridge_fan_speed, 1) /gmex;
  781. $gcode =~ s/^;_BRIDGE_FAN_END\n/ $gcodegen->set_fan($fan_speed, 1) /gmex;
  782. }
  783. return $gcode;
  784. };
  785. # do all objects for each layer
  786. if ($Slic3r::Config->complete_objects) {
  787. # print objects from the smallest to the tallest to avoid collisions
  788. # when moving onto next object starting point
  789. my @obj_idx = sort { $self->objects->[$a]->layer_count <=> $self->objects->[$b]->layer_count } 0..$#{$self->objects};
  790. my $finished_objects = 0;
  791. for my $obj_idx (@obj_idx) {
  792. for my $copy (@{ $self->objects->[$obj_idx]->copies }) {
  793. # move to the origin position for the copy we're going to print.
  794. # this happens before Z goes down to layer 0 again, so that
  795. # no collision happens hopefully.
  796. if ($finished_objects > 0) {
  797. $gcodegen->set_shift(map $shift[$_] + unscale $copy->[$_], X,Y);
  798. print $fh $gcodegen->retract;
  799. print $fh $gcodegen->G0(Slic3r::Point->new(0,0), undef, 0, 'move to origin position for next object');
  800. }
  801. for my $layer_id (0..$#{$self->objects->[$obj_idx]->layers}) {
  802. # if we are printing the bottom layer of an object, and we have already finished
  803. # another one, set first layer temperatures. this happens before the Z move
  804. # is triggered, so machine has more time to reach such temperatures
  805. if ($layer_id == 0 && $finished_objects > 0) {
  806. printf $fh $gcodegen->set_bed_temperature($Slic3r::Config->first_layer_bed_temperature),
  807. if $Slic3r::Config->first_layer_bed_temperature;
  808. $print_first_layer_temperature->();
  809. }
  810. print $fh $extrude_layer->($layer_id, [[ $obj_idx, $copy ]]);
  811. }
  812. $finished_objects++;
  813. }
  814. }
  815. } else {
  816. for my $layer_id (0..$self->layer_count-1) {
  817. my @object_copies = ();
  818. for my $obj_idx (grep $self->objects->[$_]->layers->[$layer_id], 0..$#{$self->objects}) {
  819. push @object_copies, map [ $obj_idx, $_ ], @{ $self->objects->[$obj_idx]->copies };
  820. }
  821. print $fh $extrude_layer->($layer_id, \@object_copies);
  822. }
  823. }
  824. # save statistic data
  825. $self->total_extrusion_length($gcodegen->total_extrusion_length);
  826. # write end commands to file
  827. print $fh $gcodegen->retract;
  828. print $fh $gcodegen->set_fan(0);
  829. printf $fh "%s\n", $Slic3r::Config->replace_options($Slic3r::Config->end_gcode);
  830. printf $fh "; filament used = %.1fmm (%.1fcm3)\n",
  831. $self->total_extrusion_length, $self->total_extrusion_volume;
  832. if ($Slic3r::Config->gcode_comments) {
  833. # append full config
  834. print $fh "\n";
  835. foreach my $opt_key (sort keys %{$Slic3r::Config}) {
  836. next if $Slic3r::Config::Options->{$opt_key}{shortcut};
  837. next if $Slic3r::Config::Options->{$opt_key}{gui_only};
  838. printf $fh "; %s = %s\n", $opt_key, $Slic3r::Config->serialize($opt_key);
  839. }
  840. }
  841. # close our gcode file
  842. close $fh;
  843. }
  844. sub total_extrusion_volume {
  845. my $self = shift;
  846. return $self->total_extrusion_length * ($self->extruders->[0]->filament_diameter**2) * PI/4 / 1000;
  847. }
  848. # this method will return the supplied input file path after expanding its
  849. # format variables with their values
  850. sub expanded_output_filepath {
  851. my $self = shift;
  852. my ($path, $input_file) = @_;
  853. # if no input file was supplied, take the first one from our objects
  854. $input_file ||= $self->objects->[0]->input_file;
  855. return undef if !defined $input_file;
  856. # if output path is an existing directory, we take that and append
  857. # the specified filename format
  858. $path = File::Spec->join($path, $Slic3r::Config->output_filename_format) if ($path && -d $path);
  859. # if no explicit output file was defined, we take the input
  860. # file directory and append the specified filename format
  861. $path ||= (fileparse($input_file))[1] . $Slic3r::Config->output_filename_format;
  862. my $input_filename = my $input_filename_base = basename($input_file);
  863. $input_filename_base =~ s/\.(?:stl|amf(?:\.xml)?)$//i;
  864. return $Slic3r::Config->replace_options($path, {
  865. input_filename => $input_filename,
  866. input_filename_base => $input_filename_base,
  867. %{ $self->extra_variables },
  868. });
  869. }
  870. 1;