Fix raft_layers according to the new support material logic

This commit is contained in:
Alessandro Ranellucci 2013-11-02 11:16:44 +01:00
parent d7656f5fdc
commit 3f7adfc07d
2 changed files with 27 additions and 20 deletions

View File

@ -25,30 +25,18 @@ sub BUILD {
$self->init_config; $self->init_config;
# make layers taking custom heights into account # 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 # add raft layers
for my $id (0 .. $self->config->raft_layers-1) { if ($self->config->raft_layers > 0) {
$height = ($id == 0) $print_z += $Slic3r::Config->get_value('first_layer_height');
? $Slic3r::Config->get_value('first_layer_height') $print_z += $Slic3r::Config->layer_height * ($self->config->raft_layers - 1);
: $Slic3r::Config->layer_height; $id += $self->config->raft_layers;
$print_z += $height;
push @{$self->layers}, Slic3r::Layer->new(
object => $self,
id => $id,
height => $height,
print_z => $print_z,
slice_z => -1,
);
} }
# loop until we have at least one layer and the max slice_z reaches the object height # loop until we have at least one layer and the max slice_z reaches the object height
my $max_z = unscale $self->size->[Z]; my $max_z = unscale $self->size->[Z];
while (!@{$self->layers} || ($slice_z - $height) <= $max_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 # assign the default height to the layer according to the general settings
$height = ($id == 0) $height = ($id == 0)
? $Slic3r::Config->get_value('first_layer_height') ? $Slic3r::Config->get_value('first_layer_height')
@ -77,6 +65,7 @@ sub BUILD {
print_z => $print_z, print_z => $print_z,
slice_z => scale $slice_z, slice_z => scale $slice_z,
); );
$id++;
$slice_z += $height/2; # add the other half layer $slice_z += $height/2; # add the other half layer
} }

View File

@ -80,8 +80,14 @@ sub contact_area {
# determine contact areas # determine contact areas
my %contact = (); # contact_z => [ polygons ] my %contact = (); # contact_z => [ polygons ]
my %overhang = (); # contact_z => [ polygons ] - this stores the actual overhang supported by each contact layer my %overhang = (); # contact_z => [ polygons ] - this stores the actual overhang supported by each contact layer
for my $layer_id (1 .. $#{$object->layers}) { for my $layer_id (0 .. $#{$object->layers}) {
last if $layer_id > $self->config->raft_layers && !$self->config->support_material; 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 $layer = $object->layers->[$layer_id];
my $lower_layer = $object->layers->[$layer_id-1]; 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 a threshold angle was specified, use a different logic for detecting overhangs.
if (defined $threshold_rad 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 my $d = defined $threshold_rad
? scale $lower_layer->height * ((cos $threshold_rad) / (sin $threshold_rad)) ? scale $lower_layer->height * ((cos $threshold_rad) / (sin $threshold_rad))
: 0; : 0;
@ -233,6 +240,17 @@ sub support_layers_z {
shift @z while @z && $z[0] <= $first_layer_height; shift @z while @z && $z[0] <= $first_layer_height;
unshift @z, $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--) { for (my $i = $#z; $i >= 0; $i--) {
my $target_height = $support_material_height; my $target_height = $support_material_height;
if ($i > 0 && $top{ $z[$i-1] }) { if ($i > 0 && $top{ $z[$i-1] }) {