diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 1d52ffc6a..b0ffbf936 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -25,30 +25,18 @@ sub BUILD { $self->init_config; # make layers taking custom heights into account - my $print_z = my $slice_z = my $height = 0; + my $print_z = my $slice_z = my $height = my $id = 0; # add raft layers - for my $id (0 .. $self->config->raft_layers-1) { - $height = ($id == 0) - ? $Slic3r::Config->get_value('first_layer_height') - : $Slic3r::Config->layer_height; - - $print_z += $height; - - push @{$self->layers}, Slic3r::Layer->new( - object => $self, - id => $id, - height => $height, - print_z => $print_z, - slice_z => -1, - ); + 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); + $id += $self->config->raft_layers; } # loop until we have at least one layer and the max slice_z reaches the object height my $max_z = unscale $self->size->[Z]; while (!@{$self->layers} || ($slice_z - $height) <= $max_z) { - my $id = $#{$self->layers} + 1; - # assign the default height to the layer according to the general settings $height = ($id == 0) ? $Slic3r::Config->get_value('first_layer_height') @@ -77,6 +65,7 @@ sub BUILD { print_z => $print_z, slice_z => scale $slice_z, ); + $id++; $slice_z += $height/2; # add the other half layer } diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index 3a4466ba8..4765dee8b 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -80,8 +80,14 @@ sub contact_area { # determine contact areas my %contact = (); # contact_z => [ polygons ] my %overhang = (); # contact_z => [ polygons ] - this stores the actual overhang supported by each contact layer - for my $layer_id (1 .. $#{$object->layers}) { - last if $layer_id > $self->config->raft_layers && !$self->config->support_material; + for my $layer_id (0 .. $#{$object->layers}) { + if ($self->config->raft_layers == 0) { + next if $layer_id == 0; + } elsif (!$self->config->support_material) { + # if we are only going to generate raft just check + # the 'overhangs' of the first object layer + last if $layer_id > 0; + } my $layer = $object->layers->[$layer_id]; my $lower_layer = $object->layers->[$layer_id-1]; @@ -93,7 +99,8 @@ sub contact_area { # If a threshold angle was specified, use a different logic for detecting overhangs. if (defined $threshold_rad - || $layer_id <= $self->config->support_material_enforce_layers + $self->config->raft_layers) { + || $layer_id < $self->config->support_material_enforce_layers + || $self->config->raft_layers > 0) { my $d = defined $threshold_rad ? scale $lower_layer->height * ((cos $threshold_rad) / (sin $threshold_rad)) : 0; @@ -233,6 +240,17 @@ sub support_layers_z { shift @z while @z && $z[0] <= $first_layer_height; unshift @z, $first_layer_height; + # add raft layers by dividing the space between first layer and + # first contact layer evenly + if ($self->config->raft_layers > 1) { + # $z[1] is last raft layer (contact layer for the first layer object) + my $height = ($z[1] - $z[0]) / ($self->config->raft_layers - 1); + splice @z, 1, 0, + map { int($_*100)/100 } + map { $z[0] + $height * $_ } + 0..($self->config->raft_layers - 1); + } + for (my $i = $#z; $i >= 0; $i--) { my $target_height = $support_material_height; if ($i > 0 && $top{ $z[$i-1] }) {