Skip to content

Commit

Permalink
Bugfix: first layer extrusion width was computed on general layer hei…
Browse files Browse the repository at this point in the history
…ght rather than first layer height. #465
  • Loading branch information
alranel committed Jun 23, 2012
1 parent 48addf8 commit a9d480f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/Slic3r/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ sub validate {
# calculate flow
$Slic3r::flow->calculate($Slic3r::extrusion_width);
if ($Slic3r::first_layer_extrusion_width) {
$Slic3r::first_layer_flow = Slic3r::Flow->new;
$Slic3r::first_layer_flow = Slic3r::Flow->new(layer_height => $Slic3r::_first_layer_height);
$Slic3r::first_layer_flow->calculate($Slic3r::first_layer_extrusion_width);
}
$Slic3r::perimeters_flow->calculate($Slic3r::perimeters_extrusion_width || $Slic3r::extrusion_width);
Expand Down
23 changes: 13 additions & 10 deletions lib/Slic3r/Flow.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use Moo;

use Slic3r::Geometry qw(PI);

has 'width' => (is => 'rw');
has 'min_spacing' => (is => 'rw');
has 'spacing' => (is => 'rw');
has 'width' => (is => 'rw');
has 'min_spacing' => (is => 'rw');
has 'spacing' => (is => 'rw');
has 'layer_height' => (is => 'lazy', builder => 1);

This comment has been minimized.

Copy link
@henrikbrixandersen

henrikbrixandersen Jun 26, 2012

Member

Lazy initialization is no good here, since it caches the value - thus, changing $Slic3r::layer_height from the GUI will not be reflected by $self->layer_height.

This comment has been minimized.

Copy link
@alranel

alranel Jun 27, 2012

Author Member

You're right, good catch. I think Flow objects have to be reinitialized each time config is validated.


sub _build_layer_height { $Slic3r::layer_height }

sub calculate {
my $self = shift;
Expand All @@ -14,20 +17,20 @@ sub calculate {
my ($flow_width, $min_flow_spacing, $flow_spacing);
if ($extrusion_width) {
$flow_width = $extrusion_width =~ /^(\d+(?:\.\d+)?)%$/
? ($Slic3r::layer_height * $1 / 100)
? ($self->layer_height * $1 / 100)
: $extrusion_width;
} else {
# here we calculate a sane default by matching the flow speed (at the nozzle)
# and the feed rate
my $volume = ($Slic3r::nozzle_diameter**2) * PI/4;
my $shape_threshold = $Slic3r::nozzle_diameter * $Slic3r::layer_height
+ ($Slic3r::layer_height**2) * PI/4;
my $shape_threshold = $Slic3r::nozzle_diameter * $self->layer_height
+ ($self->layer_height**2) * PI/4;
if ($volume >= $shape_threshold) {
# rectangle with semicircles at the ends
$flow_width = (($Slic3r::nozzle_diameter**2) * PI + ($Slic3r::layer_height**2) * (4 - PI)) / (4 * $Slic3r::layer_height);
$flow_width = (($Slic3r::nozzle_diameter**2) * PI + ($self->layer_height**2) * (4 - PI)) / (4 * $self->layer_height);
} else {
# rectangle with squished semicircles at the ends
$flow_width = $Slic3r::nozzle_diameter * ($Slic3r::nozzle_diameter/$Slic3r::layer_height - 4/PI + 1);
$flow_width = $Slic3r::nozzle_diameter * ($Slic3r::nozzle_diameter/$self->layer_height - 4/PI + 1);
}

my $min_flow_width = $Slic3r::nozzle_diameter * 1.05;
Expand All @@ -36,9 +39,9 @@ sub calculate {
$flow_width = $min_flow_width if $flow_width < $min_flow_width;
}

if ($flow_width >= ($Slic3r::nozzle_diameter + $Slic3r::layer_height)) {
if ($flow_width >= ($Slic3r::nozzle_diameter + $self->layer_height)) {
# rectangle with semicircles at the ends
$min_flow_spacing = $flow_width - $Slic3r::layer_height * (1 - PI/4);
$min_flow_spacing = $flow_width - $self->layer_height * (1 - PI/4);
} else {
# rectangle with shrunk semicircles at the ends
$min_flow_spacing = $flow_width * (1 - PI/4) + $Slic3r::nozzle_diameter * PI/4;
Expand Down

0 comments on commit a9d480f

Please sign in to comment.