From 91bcfc8a74425b1bfe3577460e5c3f48bcf17b9e Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 22 Feb 2013 16:08:11 +0100 Subject: [PATCH] Remove $Slic3r::flow and $Slic3r::first_layer_flow --- lib/Slic3r.pm | 5 ----- lib/Slic3r/Layer.pm | 7 +++---- lib/Slic3r/Layer/Region.pm | 12 +++++------- lib/Slic3r/Print.pm | 36 +++++++++++++++--------------------- lib/Slic3r/Print/Object.pm | 2 +- 5 files changed, 24 insertions(+), 38 deletions(-) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index f4e26b98a0..75ea26ed38 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -69,12 +69,7 @@ use constant SMALL_PERIMETER_LENGTH => (6.5 / SCALING_FACTOR) * 2 * PI; use constant LOOP_CLIPPING_LENGTH_OVER_SPACING => 0.15; use constant PERIMETER_INFILL_OVERLAP_OVER_SPACING => 0.45; -# The following variables hold the objects used throughout the slicing -# process. They should belong to the Print object, but we are keeping -# them here because it makes accessing them slightly faster. our $Config; -our $flow; -our $first_layer_flow; sub parallelize { my %params = @_; diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index cedd234c2c..9138aaf85a 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -13,7 +13,6 @@ has 'slicing_errors' => (is => 'rw'); has 'slice_z' => (is => 'lazy'); has 'print_z' => (is => 'lazy'); has 'height' => (is => 'lazy'); -has 'flow' => (is => 'lazy'); # collection of expolygons generated by slicing the original geometry; # also known as 'islands' (all regions are merged here) @@ -57,8 +56,6 @@ sub _build_height { return $self->id == 0 ? $Slic3r::Config->get_value('first_layer_height') : $Slic3r::Config->layer_height; } -sub _build_flow { $Slic3r::flow } - # layer height of contact paths in unscaled coordinates sub support_material_contact_height { my $self = shift; @@ -69,7 +66,8 @@ sub support_material_contact_height { # - we should sum our height with the actual upper layers height (which might be different) # - we should use the actual flow of the upper layer bridges, not the default one # ...but we're close enough for now - return 2*$self->height - $self->flow->nozzle_diameter; + my $upper_layer = $self->object->layers->[ $self->id + 1 ] // $self; + return 2*$self->height - $upper_layer->infill_flow->bridge_width; } # Z used for printing support material contact in scaled coordinates @@ -115,6 +113,7 @@ sub make_perimeters { sub support_islands_enclose_line { my $self = shift; my ($line) = @_; + return 0 if !$self->support_islands; # why can we arrive here if there are no support islands? return (first { $_->encloses_line($line) } @{$self->support_islands}) ? 1 : 0; } diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 027a9bd587..68a227846b 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -57,13 +57,11 @@ sub _update_flows { my $self = shift; return if !$self->region; - $self->perimeter_flow($self->id == 0 - ? $self->region->first_layer_flows->{perimeter} - : $self->region->flows->{perimeter}); + $self->perimeter_flow + ($self->region->first_layer_flows->{perimeter} || $self->region->flows->{perimeter}); - $self->infill_flow($self->id == 0 - ? $self->region->first_layer_flows->{infill} - : $self->region->flows->{infill}); + $self->infill_flow + ($self->region->first_layer_flows->{infill} || $self->region->flows->{infill}); } sub _build_overhang_width { @@ -471,7 +469,7 @@ sub process_bridges { # offset the contour and intersect it with the internal surfaces to discover # which of them has contact with our bridge my @supporting_surfaces = (); - my ($contour_offset) = $expolygon->contour->offset(scale $self->flow->spacing * sqrt(2)); + my ($contour_offset) = $expolygon->contour->offset(scale $self->infill_flow->spacing * sqrt(2)); foreach my $internal_surface (@internal_surfaces) { my $intersection = intersection_ex([$contour_offset], [$internal_surface->p]); if (@$intersection) { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d22bcb493b..4263c68b08 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -195,15 +195,6 @@ sub init_extruders { ); } - # calculate default flows - $Slic3r::flow = $self->extruders->[0]->make_flow( - width => $self->config->extrusion_width, - ); - $Slic3r::first_layer_flow = $self->extruders->[0]->make_flow( - layer_height => $self->config->get_value('first_layer_height'), - width => $self->config->first_layer_extrusion_width, - ); - # calculate regions' flows for my $region_id (0 .. $#{$self->regions}) { my $region = $self->regions->[$region_id]; @@ -219,7 +210,7 @@ sub init_extruders { $region->first_layer_flows->{$_} = $region->extruders->{$_}->make_flow( layer_height => $self->config->get_value('first_layer_height'), width => $self->config->first_layer_extrusion_width, - ); + ) if $self->config->first_layer_extrusion_width; } } @@ -234,9 +225,6 @@ sub init_extruders { width => $self->config->first_layer_extrusion_width, )); } - - Slic3r::debugf "Default flow width = %s (spacing = %s)\n", - $Slic3r::flow->width, $Slic3r::flow->spacing; } sub object_copies { @@ -573,7 +561,10 @@ sub make_skirt { my $convex_hull = convex_hull(\@points); my @extruded_length = (); # for each extruder - my $spacing = $Slic3r::first_layer_flow->spacing; + + # 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 @extruders_e_per_mm = (); my $extruder_idx = 0; @@ -612,7 +603,9 @@ sub make_brim { my $self = shift; return unless $Slic3r::Config->brim_width > 0; - my $grow_distance = $Slic3r::first_layer_flow->scaled_width / 2; + my $flow = $self->objects->[0]->layers->[0]->regions->[0]->perimeter_flow; + + my $grow_distance = $flow->scaled_width / 2; my @islands = (); # array of polygons foreach my $obj_idx (0 .. $#{$self->objects}) { my $layer0 = $self->objects->[$obj_idx]->layers->[0]; @@ -627,18 +620,19 @@ sub make_brim { } # if brim touches skirt, make it around skirt too - if ($Slic3r::Config->skirt_distance + (($Slic3r::Config->skirts - 1) * $Slic3r::first_layer_flow->spacing) <= $Slic3r::Config->brim_width) { + # 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) { push @islands, map $_->unpack->split_at_first_point->polyline->grow($grow_distance), @{$self->skirt}; } - my $num_loops = sprintf "%.0f", $Slic3r::Config->brim_width / $Slic3r::first_layer_flow->width; + my $num_loops = sprintf "%.0f", $Slic3r::Config->brim_width / $flow->width; for my $i (reverse 1 .. $num_loops) { # JT_SQUARE ensures no vertex is outside the given offset distance push @{$self->brim}, Slic3r::ExtrusionLoop->pack( polygon => Slic3r::Polygon->new($_), role => EXTR_ROLE_SKIRT, - flow_spacing => $Slic3r::first_layer_flow->spacing, - ) for Slic3r::Geometry::Clipper::offset(\@islands, $i * $Slic3r::first_layer_flow->scaled_spacing, undef, JT_SQUARE); + flow_spacing => $flow->spacing, + ) for Slic3r::Geometry::Clipper::offset(\@islands, $i * $flow->scaled_spacing, undef, JT_SQUARE); # TODO: we need the offset inwards/offset outwards logic to avoid overlapping extrusions } } @@ -674,8 +668,8 @@ sub write_gcode { printf $fh "; infill extrusion width = %.2fmm\n", $self->regions->[0]->flows->{infill}->width; printf $fh "; support material extrusion width = %.2fmm\n", $self->support_material_flow->width if $self->support_material_flow; - printf $fh "; first layer extrusion width = %.2fmm\n", $Slic3r::first_layer_flow->width - if $Slic3r::first_layer_flow; + printf $fh "; first layer extrusion width = %.2fmm\n", $self->regions->[0]->first_layer_flows->{perimeter}->width + if $self->regions->[0]->first_layer_flows->{perimeter}; print $fh "\n"; # set up our extruder object diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index a9fc25c345..567e37e554 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -306,7 +306,7 @@ sub detect_surfaces_type { [ map { ref $_ eq 'ARRAY' ? $_ : ref $_ eq 'Slic3r::ExPolygon' ? @$_ : $_->p } @$clip_surfaces ], 1, ); - return grep $_->contour->is_printable($layerm->flow), + return grep $_->contour->is_printable($layerm->infill_flow), map Slic3r::Surface->new(expolygon => $_, surface_type => $result_type), @$expolygons; };