diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index bd6635b7..1a1fa6f7 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -82,15 +82,13 @@ use constant LOOP_CLIPPING_LENGTH_OVER_SPACING => 0.15; use constant INFILL_OVERLAP_OVER_SPACING => 0.45; use constant EXTERNAL_INFILL_MARGIN => 3; -our $Config; - sub parallelize { my %params = @_; - if (!$params{disable} && $Slic3r::have_threads && $Config->threads > 1) { + if (!$params{disable} && $Slic3r::have_threads && $params{threads} > 1) { my @items = (ref $params{items} eq 'CODE') ? $params{items}->() : @{$params{items}}; my $q = Thread::Queue->new; - $q->enqueue(@items, (map undef, 1..$Config->threads)); + $q->enqueue(@items, (map undef, 1..$params{threads})); my $thread_cb = sub { $params{thread_cb}->($q); @@ -111,7 +109,7 @@ sub parallelize { $params{collect_cb} ||= sub {}; @_ = (); - foreach my $th (map threads->create($thread_cb), 1..$Config->threads) { + foreach my $th (map threads->create($thread_cb), 1..$params{threads}) { $params{collect_cb}->($th->join); } } else { diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 9ab5cd0f..d976e715 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -21,7 +21,6 @@ has 'retracted' => (is => 'rw', default => sub {0} ); has 'restart_extra' => (is => 'rw', default => sub {0} ); has 'e_per_mm3' => (is => 'lazy'); has 'retract_speed_mm_min' => (is => 'lazy'); -has 'scaled_wipe_distance' => (is => 'lazy'); # scaled mm has '_mm3_per_mm_cache' => (is => 'ro', default => sub {{}}); sub _build_bridge_flow { @@ -39,14 +38,14 @@ sub _build_retract_speed_mm_min { return $self->retract_speed * 60; } -sub _build_scaled_wipe_distance { - my $self = shift; +sub scaled_wipe_distance { + my ($self, $travel_speed) = shift; # how far do we move in XY at travel_speed for the time needed to consume # retract_length at retract_speed? # reduce feedrate a bit; travel speed is often too high to move on existing material # too fast = ripping of existing material; too slow = short wipe path, thus more blob - return scale($self->retract_length / $self->retract_speed * $Slic3r::Config->travel_speed * 0.8); + return scale($self->retract_length / $self->retract_speed * $travel_speed * 0.8); } sub extrude { diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index bd7faf86..42cbea13 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -157,6 +157,7 @@ sub make_fill { my $f = $self->filler($filler); $f->layer_id($layerm->id); + $f->angle($layerm->config->fill_angle); my ($params, @polylines) = $f->fill_surface( $surface, density => $density, diff --git a/lib/Slic3r/Fill/Base.pm b/lib/Slic3r/Fill/Base.pm index f7d62284..eaa922d1 100644 --- a/lib/Slic3r/Fill/Base.pm +++ b/lib/Slic3r/Fill/Base.pm @@ -4,7 +4,7 @@ use Moo; use Slic3r::Geometry qw(PI); has 'layer_id' => (is => 'rw'); -has 'angle' => (is => 'rw', default => sub { $Slic3r::Config->fill_angle }); +has 'angle' => (is => 'rw'); has 'bounding_box' => (is => 'ro', required => 0); # Slic3r::Geometry::BoundingBox object sub angles () { [0, PI/2] } diff --git a/lib/Slic3r/Flow.pm b/lib/Slic3r/Flow.pm index f4e33c69..b4aaad49 100644 --- a/lib/Slic3r/Flow.pm +++ b/lib/Slic3r/Flow.pm @@ -4,7 +4,7 @@ use Moo; use Slic3r::Geometry qw(PI scale); has 'nozzle_diameter' => (is => 'ro', required => 1); -has 'layer_height' => (is => 'ro', default => sub { $Slic3r::Config->layer_height }); +has 'layer_height' => (is => 'ro', required => 1); has 'role' => (is => 'ro', default => sub { '' }); has 'width' => (is => 'rwp', builder => 1); @@ -89,6 +89,9 @@ package Slic3r::Flow::Bridge; use Moo; extends 'Slic3r::Flow'; +# layer_height is not required in this case +has '+layer_height' => (is => 'ro', required => 0); + use Slic3r::Geometry qw(PI); sub _build_width { diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 37e88431..66292040 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -97,7 +97,7 @@ sub change_layer { $self->_layer_islands($layer->islands); $self->_upper_layer_islands($layer->upper_layer ? $layer->upper_layer->islands : []); $self->_layer_overhangs->clear; - if ($layer->id > 0 && ($layer->config->overhangs || $Slic3r::Config->start_perimeters_at_non_overhang)) { + if ($layer->id > 0 && ($layer->config->overhangs || $self->config->start_perimeters_at_non_overhang)) { $self->_layer_overhangs->append( # clone ExPolygons because they come from Surface objects but will be used outside here map $_->expolygon, map @{$_->slices->filter_by_type(S_TYPE_BOTTOM)}, @{$layer->regions} @@ -181,11 +181,11 @@ sub extrude_loop { # find candidate starting points # start looking for concave vertices not being overhangs my @concave = (); - if ($Slic3r::Config->start_perimeters_at_concave_points) { + if ($self->config->start_perimeters_at_concave_points) { @concave = $polygon->concave_points; } my @candidates = (); - if ($Slic3r::Config->start_perimeters_at_non_overhang) { + if ($self->config->start_perimeters_at_non_overhang) { @candidates = grep !$self->_layer_overhangs->contains_point($_), @concave; } if (!@candidates) { @@ -193,7 +193,7 @@ sub extrude_loop { @candidates = @concave; if (!@candidates) { # if none, look for any non-overhang vertex - if ($Slic3r::Config->start_perimeters_at_non_overhang) { + if ($self->config->start_perimeters_at_non_overhang) { @candidates = grep !$self->_layer_overhangs->contains_point($_), @$polygon; } if (!@candidates) { @@ -481,7 +481,7 @@ sub retract { if ($self->extruder->wipe && $self->wipe_path) { my @points = @{$self->wipe_path}; $wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}]); - $wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance); + $wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance($self->config->travel_speed)); } # prepare moves @@ -500,7 +500,7 @@ sub retract { my $segment_length = $line->length; # reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one # due to rounding - my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance) * 0.95; + my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance($self->config->travel_speed)) * 0.95; $retracted += $e; $gcode .= $self->G1($line->b, undef, $e, $retract->[3] . ";_WIPE"); } diff --git a/lib/Slic3r/GCode/Layer.pm b/lib/Slic3r/GCode/Layer.pm index e7c2f8b1..d41f9549 100644 --- a/lib/Slic3r/GCode/Layer.pm +++ b/lib/Slic3r/GCode/Layer.pm @@ -19,7 +19,7 @@ has '_last_obj_copy' => (is => 'rw'); sub _build_spiralvase { my $self = shift; - return $Slic3r::Config->spiral_vase + return $self->gcodegen->config->spiral_vase ? Slic3r::GCode::SpiralVase->new(config => $self->gcodegen->config) : undef; } @@ -27,7 +27,7 @@ sub _build_spiralvase { sub _build_vibration_limit { my $self = shift; - return $Slic3r::Config->vibration_limit + return $self->gcodegen->config->vibration_limit ? Slic3r::GCode::VibrationLimit->new(config => $self->gcodegen->config) : undef; } @@ -35,7 +35,7 @@ sub _build_vibration_limit { sub _build_arc_fitting { my $self = shift; - return $Slic3r::Config->gcode_arcs + return $self->gcodegen->config->gcode_arcs ? Slic3r::GCode::ArcFitting->new(config => $self->gcodegen->config) : undef; } @@ -47,41 +47,41 @@ sub process_layer { # check whether we're going to apply spiralvase logic my $spiralvase = defined $self->spiralvase - && ($layer->id > 0 || $Slic3r::Config->brim_width == 0) - && ($layer->id >= $Slic3r::Config->skirt_height) - && ($layer->id >= $Slic3r::Config->bottom_solid_layers); + && ($layer->id > 0 || $self->gcodegen->config->brim_width == 0) + && ($layer->id >= $self->gcodegen->config->skirt_height) + && ($layer->id >= $self->gcodegen->config->bottom_solid_layers); # if we're going to apply spiralvase to this layer, disable loop clipping $self->gcodegen->enable_loop_clipping(!$spiralvase); if (!$self->second_layer_things_done && $layer->id == 1) { - for my $t (grep $self->extruders->[$_], 0 .. $#{$Slic3r::Config->temperature}) { + for my $t (grep $self->extruders->[$_], 0 .. $#{$self->gcodegen->config->temperature}) { $gcode .= $self->gcodegen->set_temperature($self->extruders->[$t]->temperature, 0, $t) if $self->print->extruders->[$t]->temperature && $self->extruders->[$t]->temperature != $self->extruders->[$t]->first_layer_temperature; } - $gcode .= $self->gcodegen->set_bed_temperature($Slic3r::Config->bed_temperature) - if $Slic3r::Config->bed_temperature && $Slic3r::Config->bed_temperature != $Slic3r::Config->first_layer_bed_temperature; + $gcode .= $self->gcodegen->set_bed_temperature($self->gcodegen->config->bed_temperature) + if $self->gcodegen->config->bed_temperature && $self->gcodegen->config->bed_temperature != $self->gcodegen->config->first_layer_bed_temperature; $self->second_layer_things_done(1); } # set new layer - this will change Z and force a retraction if retract_layer_change is enabled $gcode .= $self->gcodegen->change_layer($layer); - $gcode .= $self->gcodegen->replace_variables($Slic3r::Config->layer_gcode, { + $gcode .= $self->gcodegen->replace_variables($self->gcodegen->config->layer_gcode, { layer_num => $self->gcodegen->layer->id, - }) . "\n" if $Slic3r::Config->layer_gcode; + }) . "\n" if $self->gcodegen->config->layer_gcode; # extrude skirt - if ((values %{$self->skirt_done}) < $Slic3r::Config->skirt_height && !$self->skirt_done->{$layer->print_z}) { + if ((values %{$self->skirt_done}) < $self->gcodegen->config->skirt_height && !$self->skirt_done->{$layer->print_z}) { $self->gcodegen->set_shift(@{$self->shift}); $gcode .= $self->gcodegen->set_extruder($self->extruders->[0]); # skip skirt if we have a large brim - if ($layer->id < $Slic3r::Config->skirt_height) { + if ($layer->id < $self->gcodegen->config->skirt_height) { # distribute skirt loops across all extruders my @skirt_loops = @{$self->print->skirt}; for my $i (0 .. $#skirt_loops) { # when printing layers > 0 ignore 'min_skirt_length' and # just use the 'skirts' setting; also just use the current extruder - last if ($layer->id > 0) && ($i >= $Slic3r::Config->skirts); + last if ($layer->id > 0) && ($i >= $self->gcodegen->config->skirts); $gcode .= $self->gcodegen->set_extruder($self->extruders->[ ($i/@{$self->extruders}) % @{$self->extruders} ]) if $layer->id == 0; $gcode .= $self->gcodegen->extrude_loop($skirt_loops[$i], 'skirt'); @@ -93,7 +93,7 @@ sub process_layer { # extrude brim if (!$self->brim_done) { - $gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]); + $gcode .= $self->gcodegen->set_extruder($self->extruders->[$self->gcodegen->config->support_material_extruder-1]); $self->gcodegen->set_shift(@{$self->shift}); $gcode .= $self->gcodegen->extrude_loop($_, 'brim') for @{$self->print->brim}; $self->brim_done(1); @@ -110,12 +110,12 @@ sub process_layer { # and also because we avoid travelling on other things when printing it if ($self->print->has_support_material && $layer->isa('Slic3r::Layer::Support')) { if ($layer->support_interface_fills->count > 0) { - $gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_interface_extruder-1]); + $gcode .= $self->gcodegen->set_extruder($self->extruders->[$self->gcodegen->config->support_material_interface_extruder-1]); $gcode .= $self->gcodegen->extrude_path($_, 'support material interface') for @{$layer->support_interface_fills->chained_path_from($self->gcodegen->last_pos, 0)}; } if ($layer->support_fills->count > 0) { - $gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]); + $gcode .= $self->gcodegen->set_extruder($self->extruders->[$self->gcodegen->config->support_material_extruder-1]); $gcode .= $self->gcodegen->extrude_path($_, 'support material') for @{$layer->support_fills->chained_path_from($self->gcodegen->last_pos, 0)}; } @@ -134,7 +134,7 @@ sub process_layer { my $region = $self->print->regions->[$region_id]; my @islands = (); - if ($Slic3r::Config->avoid_crossing_perimeters) { + if ($self->gcodegen->config->avoid_crossing_perimeters) { push @islands, { perimeters => [], fills => [] } for 1 .. (@{$layer->slices} || 1); # make sure we have at least one island hash to avoid failure of the -1 subscript below PERIMETER: foreach my $perimeter (@{$layerm->perimeters}) { @@ -165,7 +165,7 @@ sub process_layer { foreach my $island (@islands) { # give priority to infill if we were already using its extruder and it wouldn't # be good for perimeters - if ($Slic3r::Config->infill_first + if ($self->gcodegen->config->infill_first || ($self->gcodegen->multiple_extruders && $region->extruders->{infill} eq $self->gcodegen->extruder) && $region->extruders->{infill} ne $region->extruders->{perimeter}) { $gcode .= $self->_extrude_infill($island, $region); $gcode .= $self->_extrude_perimeters($island, $region); @@ -183,11 +183,11 @@ sub process_layer { # apply vibration limit if enabled $gcode = $self->vibration_limit->process($gcode) - if $Slic3r::Config->vibration_limit != 0; + if $self->gcodegen->config->vibration_limit != 0; # apply arc fitting if enabled $gcode = $self->arc_fitting->process($gcode) - if $Slic3r::Config->gcode_arcs; + if $self->gcodegen->config->gcode_arcs; return $gcode; } diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index e1d6799b..aa43c7bc 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -188,7 +188,7 @@ sub make_perimeters { @offsets = @{offset2(\@last, -(1.5*$pspacing - 1), +(0.5*$pspacing - 1))}; # look for gaps - if ($Slic3r::Config->gap_fill_speed > 0 && $self->config->fill_density > 0) { + if ($self->config->gap_fill_speed > 0 && $self->config->fill_density > 0) { my $diff = diff_ex( offset(\@last, -0.5*$pspacing), offset(\@offsets, +0.5*$pspacing), @@ -296,8 +296,8 @@ sub make_perimeters { # we continue inwards after having finished the brim # TODO: add test for perimeter order @loops = reverse @loops - if $Slic3r::Config->external_perimeters_first - || ($self->layer->id == 0 && $Slic3r::Config->brim_width > 0); + if $self->config->external_perimeters_first + || ($self->layer->id == 0 && $self->config->brim_width > 0); # append perimeters $self->perimeters->append(@loops); diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 458dd2f7..19ea2dce 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -165,7 +165,7 @@ sub delete_all_objects { sub validate { my $self = shift; - if ($Slic3r::Config->complete_objects) { + if ($self->config->complete_objects) { # check horizontal clearance { my @a = (); @@ -212,13 +212,13 @@ sub validate { # ignore the tallest *copy* (this is why we repeat height for all of them): # it will be printed as last one so its height doesn't matter pop @object_height; - if (@object_height && max(@object_height) > scale $Slic3r::Config->extruder_clearance_height) { + if (@object_height && max(@object_height) > scale $self->config->extruder_clearance_height) { die "Some objects are too tall and cannot be printed without extruder collisions.\n"; } } } - if ($Slic3r::Config->spiral_vase) { + if ($self->config->spiral_vase) { if ((map @{$_->copies}, @{$self->objects}) > 1) { die "The Spiral Vase option can only be used when printing a single object.\n"; } @@ -261,6 +261,7 @@ sub init_extruders { ? $self->extruders->[$extruder_mapping{$region_id}] : $self->extruders->[$self->config->get("${extruder_name}_extruder")-1]; $region->flows->{$_} = $region->extruders->{$_}->make_flow( + layer_height => $self->config->layer_height, width => $self->config->get("${_}_extrusion_width") || $self->config->extrusion_width, role => $_, ); @@ -274,9 +275,13 @@ sub init_extruders { # calculate support material flow # Note: we should calculate a different flow for support material interface + # TODO: support material layers have their own variable layer heights, so we + # probably need a DynamicFlow object that calculates flow on the fly + # (or the Flow object must support a mutable layer_height) if ($self->has_support_material) { my $extruder = $self->extruders->[$self->config->support_material_extruder-1]; $self->support_material_flow($extruder->make_flow( + layer_height => $self->config->layer_height, # WRONG! width => $self->config->support_material_extrusion_width || $self->config->extrusion_width, role => 'support_material', )); @@ -420,6 +425,7 @@ sub process { my $object = $self->objects->[$_[0]]; Slic3r::parallelize( + threads => $self->config->threads, items => sub { my @items = (); # [layer_id, region_id] for my $region_id (0 .. ($self->regions_count-1)) { @@ -493,10 +499,10 @@ sub export_gcode { $self->write_gcode($params{output_fh} || $output_file); # run post-processing scripts - if (@{$Slic3r::Config->post_process}) { + if (@{$self->config->post_process}) { $status_cb->(95, "Running post-processing scripts"); - $Slic3r::Config->setenv; - for (@{$Slic3r::Config->post_process}) { + $self->config->setenv; + for (@{$self->config->post_process}) { Slic3r::debugf " '%s' '%s'\n", $_, $output_file; system($_, $output_file); } @@ -595,8 +601,8 @@ EOF sub make_skirt { my $self = shift; - return unless $Slic3r::Config->skirts > 0 - || ($Slic3r::Config->ooze_prevention && @{$self->extruders} > 1); + return unless $self->config->skirts > 0 + || ($self->config->ooze_prevention && @{$self->extruders} > 1); $self->skirt->clear; # method must be idempotent @@ -604,12 +610,12 @@ sub make_skirt { my @points = (); foreach my $obj_idx (0 .. $#{$self->objects}) { my $object = $self->objects->[$obj_idx]; - my @layers = map $object->layers->[$_], 0..min($Slic3r::Config->skirt_height-1, $#{$object->layers}); + my @layers = map $object->layers->[$_], 0..min($self->config->skirt_height-1, $#{$object->layers}); my @layer_points = ( (map @$_, map @$_, map @{$_->slices}, @layers), ); if (@{ $object->support_layers }) { - my @support_layers = map $object->support_layers->[$_], 0..min($Slic3r::Config->skirt_height-1, $#{$object->support_layers}); + my @support_layers = map $object->support_layers->[$_], 0..min($self->config->skirt_height-1, $#{$object->support_layers}); push @layer_points, (map @{$_->polyline}, map @{$_->support_fills}, grep $_->support_fills, @support_layers), (map @{$_->polyline}, map @{$_->support_interface_fills}, grep $_->support_interface_fills, @support_layers); @@ -626,14 +632,14 @@ sub make_skirt { # TODO: use each extruder's own flow my $spacing = $self->objects->[0]->layers->[0]->regions->[0]->perimeter_flow->spacing; - my $first_layer_height = $Slic3r::Config->get_value('first_layer_height'); + my $first_layer_height = $self->config->get_value('first_layer_height'); my @extruders_e_per_mm = (); my $extruder_idx = 0; # draw outlines from outside to inside # loop while we have less skirts than required or any extruder hasn't reached the min length if any - my $distance = scale $Slic3r::Config->skirt_distance; - for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) { + my $distance = scale $self->config->skirt_distance; + for (my $i = $self->config->skirts; $i > 0; $i--) { $distance += scale $spacing; my $loop = offset([$convex_hull], $distance, 1, JT_ROUND, scale(0.1))->[0]; $self->skirt->append(Slic3r::ExtrusionLoop->new( @@ -642,12 +648,12 @@ sub make_skirt { flow_spacing => $spacing, )); - if ($Slic3r::Config->min_skirt_length > 0) { + if ($self->config->min_skirt_length > 0) { $extruded_length[$extruder_idx] ||= 0; $extruders_e_per_mm[$extruder_idx] ||= $self->extruders->[$extruder_idx]->e_per_mm($spacing, $first_layer_height); $extruded_length[$extruder_idx] += unscale $loop->length * $extruders_e_per_mm[$extruder_idx]; - $i++ if defined first { ($extruded_length[$_] // 0) < $Slic3r::Config->min_skirt_length } 0 .. $#{$self->extruders}; - if ($extruded_length[$extruder_idx] >= $Slic3r::Config->min_skirt_length) { + $i++ if defined first { ($extruded_length[$_] // 0) < $self->config->min_skirt_length } 0 .. $#{$self->extruders}; + if ($extruded_length[$extruder_idx] >= $self->config->min_skirt_length) { if ($extruder_idx < $#{$self->extruders}) { $extruder_idx++; next; @@ -661,7 +667,7 @@ sub make_skirt { sub make_brim { my $self = shift; - return unless $Slic3r::Config->brim_width > 0; + return unless $self->config->brim_width > 0; $self->brim->clear; # method must be idempotent @@ -691,12 +697,12 @@ sub make_brim { # if brim touches skirt, make it around skirt too # TODO: calculate actual skirt width (using each extruder's flow in multi-extruder setups) - if ($Slic3r::Config->skirt_distance + (($Slic3r::Config->skirts - 1) * $flow->spacing) <= $Slic3r::Config->brim_width) { + if ($self->config->skirt_distance + (($self->config->skirts - 1) * $flow->spacing) <= $self->config->brim_width) { push @islands, map @{$_->split_at_first_point->polyline->grow($grow_distance)}, @{$self->skirt}; } my @loops = (); - my $num_loops = sprintf "%.0f", $Slic3r::Config->brim_width / $flow->width; + my $num_loops = sprintf "%.0f", $self->config->brim_width / $flow->width; for my $i (reverse 1 .. $num_loops) { # JT_SQUARE ensures no vertex is outside the given offset distance # -0.5 because islands are not represented by their centerlines @@ -730,14 +736,14 @@ sub write_gcode { printf $fh "; generated by Slic3r $Slic3r::VERSION on %04d-%02d-%02d at %02d:%02d:%02d\n\n", $lt[5] + 1900, $lt[4]+1, $lt[3], $lt[2], $lt[1], $lt[0]; - print $fh "; $_\n" foreach split /\R/, $Slic3r::Config->notes; - print $fh "\n" if $Slic3r::Config->notes; + print $fh "; $_\n" foreach split /\R/, $self->config->notes; + print $fh "\n" if $self->config->notes; for (qw(layer_height perimeters top_solid_layers bottom_solid_layers fill_density perimeter_speed infill_speed travel_speed)) { - printf $fh "; %s = %s\n", $_, $Slic3r::Config->$_; + printf $fh "; %s = %s\n", $_, $self->config->$_; } for (qw(nozzle_diameter filament_diameter extrusion_multiplier)) { - printf $fh "; %s = %s\n", $_, $Slic3r::Config->$_->[0]; + printf $fh "; %s = %s\n", $_, $self->config->$_->[0]; } printf $fh "; perimeters extrusion width = %.2fmm\n", $self->regions->[0]->flows->{perimeter}->width; printf $fh "; infill extrusion width = %.2fmm\n", $self->regions->[0]->flows->{infill}->width; @@ -756,11 +762,11 @@ sub write_gcode { extruders => $self->extruders, # we should only pass the *used* extruders (but maintain the Tx indices right!) layer_count => $self->layer_count, ); - print $fh "G21 ; set units to millimeters\n" if $Slic3r::Config->gcode_flavor ne 'makerware'; - print $fh $gcodegen->set_fan(0, 1) if $Slic3r::Config->cooling && $Slic3r::Config->disable_fan_first_layers; + print $fh "G21 ; set units to millimeters\n" if $self->config->gcode_flavor ne 'makerware'; + print $fh $gcodegen->set_fan(0, 1) if $self->config->cooling && $self->config->disable_fan_first_layers; # set bed temperature - if ((my $temp = $Slic3r::Config->first_layer_bed_temperature) && $Slic3r::Config->start_gcode !~ /M(?:190|140)/i) { + if ((my $temp = $self->config->first_layer_bed_temperature) && $self->config->start_gcode !~ /M(?:190|140)/i) { printf $fh $gcodegen->set_bed_temperature($temp, 1); } @@ -768,7 +774,7 @@ sub write_gcode { my $print_first_layer_temperature = sub { my ($wait) = @_; - return if $Slic3r::Config->start_gcode =~ /M(?:109|104)/i; + return if $self->config->start_gcode =~ /M(?:109|104)/i; for my $t (0 .. $#{$self->extruders}) { my $temp = $self->extruders->[$t]->first_layer_temperature; $temp += $self->config->standby_temperature_delta if $self->config->ooze_prevention; @@ -776,14 +782,14 @@ sub write_gcode { } }; $print_first_layer_temperature->(0); - printf $fh "%s\n", $gcodegen->replace_variables($Slic3r::Config->start_gcode); + printf $fh "%s\n", $gcodegen->replace_variables($self->config->start_gcode); $print_first_layer_temperature->(1); # set other general things - print $fh "G90 ; use absolute coordinates\n" if $Slic3r::Config->gcode_flavor ne 'makerware'; - if ($Slic3r::Config->gcode_flavor =~ /^(?:reprap|teacup)$/) { + print $fh "G90 ; use absolute coordinates\n" if $self->config->gcode_flavor ne 'makerware'; + if ($self->config->gcode_flavor =~ /^(?:reprap|teacup)$/) { printf $fh $gcodegen->reset_e; - if ($Slic3r::Config->use_relative_e_distances) { + if ($self->config->use_relative_e_distances) { print $fh "M83 ; use relative distances for extrusion\n"; } else { print $fh "M82 ; use absolute distances for extrusion\n"; @@ -795,7 +801,7 @@ sub write_gcode { print $fh $gcodegen->set_extruder($self->extruders->[0]); # initialize a motion planner for object-to-object travel moves - if ($Slic3r::Config->avoid_crossing_perimeters) { + if ($self->config->avoid_crossing_perimeters) { my $distance_from_objects = 1; # compute the offsetted convex hull for each object and repeat it for each copy. my @islands = (); @@ -837,7 +843,7 @@ sub write_gcode { ); # do all objects for each layer - if ($Slic3r::Config->complete_objects) { + if ($self->config->complete_objects) { # print objects from the smallest to the tallest to avoid collisions # when moving onto next object starting point my @obj_idx = sort { $self->objects->[$a]->size->[Z] <=> $self->objects->[$b]->size->[Z] } 0..$#{$self->objects}; @@ -866,8 +872,8 @@ sub write_gcode { # another one, set first layer temperatures. this happens before the Z move # is triggered, so machine has more time to reach such temperatures if ($layer->id == 0 && $finished_objects > 0) { - printf $fh $gcodegen->set_bed_temperature($Slic3r::Config->first_layer_bed_temperature), - if $Slic3r::Config->first_layer_bed_temperature; + printf $fh $gcodegen->set_bed_temperature($self->config->first_layer_bed_temperature), + if $self->config->first_layer_bed_temperature; $print_first_layer_temperature->(); } print $fh $buffer->append( @@ -918,7 +924,7 @@ sub write_gcode { # write end commands to file print $fh $gcodegen->retract if $gcodegen->extruder; # empty prints don't even set an extruder print $fh $gcodegen->set_fan(0); - printf $fh "%s\n", $gcodegen->replace_variables($Slic3r::Config->end_gcode); + printf $fh "%s\n", $gcodegen->replace_variables($self->config->end_gcode); foreach my $extruder (@{$self->extruders}) { printf $fh "; filament used = %.1fmm (%.1fcm3)\n", diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 30b577fb..d7d8f00d 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -127,8 +127,8 @@ sub slice { # add raft layers if ($self->config->raft_layers > 0) { - $print_z += $Slic3r::Config->get_value('first_layer_height'); - $print_z += $Slic3r::Config->layer_height * ($self->config->raft_layers - 1); + $print_z += $self->config->get_value('first_layer_height'); + $print_z += $self->config->layer_height * ($self->config->raft_layers - 1); $id += $self->config->raft_layers; } @@ -137,8 +137,8 @@ sub slice { while (!@{$self->layers} || ($slice_z - $height) <= $max_z) { # assign the default height to the layer according to the general settings $height = ($id == 0) - ? $Slic3r::Config->get_value('first_layer_height') - : $Slic3r::Config->layer_height; + ? $self->config->get_value('first_layer_height') + : $self->config->layer_height; # look for an applicable custom range if (my $range = first { $_->[0] <= $slice_z && $_->[1] > $slice_z } @{$self->layer_height_ranges}) { @@ -346,6 +346,7 @@ sub make_perimeters { } Slic3r::parallelize( + threads => $self->config->threads, items => sub { 0 .. ($self->layer_count-1) }, thread_cb => sub { my $q = shift; diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index d4fb2922..291268bb 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -179,7 +179,7 @@ sub contact_area { ###$contact_z = $layer->print_z - $layer->height; # ignore this contact area if it's too low - next if $contact_z < $Slic3r::Config->get_value('first_layer_height'); + next if $contact_z < $self->config->get_value('first_layer_height'); $contact{$contact_z} = [ @contact ]; $overhang{$contact_z} = [ @overhang ]; @@ -609,6 +609,7 @@ sub generate_toolpaths { }; Slic3r::parallelize( + threads => $self->config->threads, items => [ 0 .. $#{$object->support_layers} ], thread_cb => sub { my $q = shift;