From 0da71dbdfa2ebdf35a34fc8354f71689e6f32b23 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 23 Dec 2012 20:20:17 +0100 Subject: [PATCH] Fix regression causing wrong number of solid shells when using fill_density = 0 (includes regression test) --- MANIFEST | 1 + lib/Slic3r/Layer/Region.pm | 5 ---- lib/Slic3r/Print/Object.pm | 9 +++++++ t/shells.t | 48 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 t/shells.t diff --git a/MANIFEST b/MANIFEST index c5869c19c..5dbd832e8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -62,6 +62,7 @@ t/geometry.t t/polyclip.t t/retraction.t t/serialize.t +t/shells.t t/stl.t t/vibrationlimit.t utils/amf-to-stl.pl diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 63e41c8c4..beb579fc3 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -396,11 +396,6 @@ sub prepare_fill_surfaces { if ($Slic3r::Config->bottom_solid_layers == 0) { $_->surface_type(S_TYPE_INTERNAL) for grep $_->surface_type == S_TYPE_BOTTOM, @{$self->fill_surfaces}; } - - # if hollow object is requested, remove internal surfaces - if ($Slic3r::Config->fill_density == 0) { - @{$self->fill_surfaces} = grep $_->surface_type != S_TYPE_INTERNAL, @{$self->fill_surfaces}; - } # turn too small internal regions into solid regions { diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 2e1930ca0..78c637aac 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -410,6 +410,15 @@ sub discover_horizontal_shells { @{$layerm->fill_surfaces} = grep $_->expolygon->area > $area_threshold, @{$layerm->fill_surfaces}; } + + for (my $i = 0; $i < $self->layer_count; $i++) { + my $layerm = $self->layers->[$i]->regions->[$region_id]; + + # if hollow object is requested, remove internal surfaces + if ($Slic3r::Config->fill_density == 0) { + @{$layerm->fill_surfaces} = grep $_->surface_type != S_TYPE_INTERNAL, @{$layerm->fill_surfaces}; + } + } } } diff --git a/t/shells.t b/t/shells.t new file mode 100644 index 000000000..ae5b7670a --- /dev/null +++ b/t/shells.t @@ -0,0 +1,48 @@ +use Test::More tests => 2; +use strict; +use warnings; + +BEGIN { + use FindBin; + use lib "$FindBin::Bin/../lib"; +} + +use List::Util qw(first); +use Slic3r; +use Slic3r::Test; + +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('skirts', 0); + $config->set('perimeters', 0); + + my $test = sub { + my ($conf) = @_; + $conf ||= $config; + + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + + my %layers_with_shells = (); # Z => $count + Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub { + my ($self, $cmd, $args, $info) = @_; + + if ($self->Z > 0) { + $layers_with_shells{$self->Z} //= 0; + $layers_with_shells{$self->Z} = 1 if $info->{extruding} && $info->{dist_XY} > 0; + } + }); + my @shells = @layers_with_shells{sort { $a <=> $b } keys %layers_with_shells}; + fail "wrong number of bottom solid layers" + unless !defined(first { !$_ } @shells[0..$config->bottom_solid_layers-1]); + fail "wrong number of top solid layers" + unless !defined(first { !$_ } @shells[-$config->top_solid_layers..-1]); + 1; + }; + + ok $test->(), "proper number of shells is applied"; + + $config->set('fill_density', 0); + ok $test->(), "proper number of shells is applied even when fill density is none"; +} + +__END__