shells.t 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. use Test::More tests => 12;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. }
  8. use List::Util qw(first);
  9. use Slic3r;
  10. use Slic3r::Test;
  11. {
  12. my $config = Slic3r::Config->new_from_defaults;
  13. $config->set('skirts', 0);
  14. $config->set('perimeters', 0);
  15. $config->set('solid_infill_speed', 99);
  16. $config->set('top_solid_infill_speed', 99);
  17. $config->set('first_layer_speed', '100%');
  18. $config->set('cooling', 0);
  19. my $test = sub {
  20. my ($conf) = @_;
  21. $conf ||= $config;
  22. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  23. my %layers_with_shells = (); # Z => $count
  24. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  25. my ($self, $cmd, $args, $info) = @_;
  26. if ($self->Z > 0) {
  27. $layers_with_shells{$self->Z} //= 0;
  28. $layers_with_shells{$self->Z} = 1
  29. if $info->{extruding}
  30. && $info->{dist_XY} > 0
  31. && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
  32. }
  33. });
  34. my @shells = @layers_with_shells{sort { $a <=> $b } keys %layers_with_shells};
  35. fail "insufficient number of bottom solid layers"
  36. unless !defined(first { !$_ } @shells[0..$config->bottom_solid_layers-1]);
  37. fail "excessive number of bottom solid layers"
  38. unless scalar(grep $_, @shells[0 .. $#shells/2]) == $config->bottom_solid_layers;
  39. fail "insufficient number of top solid layers"
  40. unless !defined(first { !$_ } @shells[-$config->top_solid_layers..-1]);
  41. fail "excessive number of top solid layers"
  42. unless scalar(grep $_, @shells[($#shells/2)..$#shells]) == $config->top_solid_layers;
  43. 1;
  44. };
  45. ok $test->(), "proper number of shells is applied";
  46. $config->set('top_solid_layers', 0);
  47. $config->set('bottom_solid_layers', 0);
  48. ok $test->(), "no shells are applied when both top and bottom are set to zero";
  49. $config->set('fill_density', 0);
  50. ok $test->(), "proper number of shells is applied even when fill density is none";
  51. }
  52. # issue #1161
  53. {
  54. my $config = Slic3r::Config->new_from_defaults;
  55. $config->set('layer_height', 0.3);
  56. $config->set('first_layer_height', '100%');
  57. $config->set('bottom_solid_layers', 0);
  58. $config->set('top_solid_layers', 3);
  59. $config->set('cooling', 0);
  60. $config->set('solid_infill_speed', 99);
  61. $config->set('top_solid_infill_speed', 99);
  62. $config->set('first_layer_speed', '100%');
  63. my $print = Slic3r::Test::init_print('V', config => $config);
  64. my %layers_with_solid_infill = (); # Z => 1
  65. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  66. my ($self, $cmd, $args, $info) = @_;
  67. $layers_with_solid_infill{$self->Z} = 1
  68. if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
  69. });
  70. is scalar(map $layers_with_solid_infill{$_}, grep $_ <= 7.2, keys %layers_with_solid_infill), 3,
  71. "correct number of top solid shells is generated in V-shaped object";
  72. }
  73. {
  74. my $config = Slic3r::Config->new_from_defaults;
  75. # we need to check against one perimeter because this test is calibrated
  76. # (shape, extrusion_width) so that perimeters cover the bottom surfaces of
  77. # their lower layer - the test checks that shells are not generated on the
  78. # above layers (thus 'across' the shadow perimeter)
  79. # the test is actually calibrated to leave a narrow bottom region for each
  80. # layer - we test that in case of fill_density = 0 such narrow shells are
  81. # discarded instead of grown
  82. $config->set('perimeters', 1);
  83. $config->set('fill_density', 0);
  84. $config->set('cooling', 0); # prevent speed alteration
  85. $config->set('first_layer_speed', '100%'); # prevent speed alteration
  86. $config->set('layer_height', 0.4);
  87. $config->set('first_layer_height', '100%');
  88. $config->set('extrusion_width', 0.55);
  89. $config->set('bottom_solid_layers', 3);
  90. $config->set('top_solid_layers', 0);
  91. $config->set('solid_infill_speed', 99);
  92. my $print = Slic3r::Test::init_print('V', config => $config);
  93. my %layers = (); # Z => 1
  94. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  95. my ($self, $cmd, $args, $info) = @_;
  96. $layers{$self->Z} = 1
  97. if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
  98. });
  99. is scalar(keys %layers), $config->bottom_solid_layers,
  100. "shells are not propagated across perimeters of the neighbor layer";
  101. }
  102. {
  103. my $config = Slic3r::Config->new_from_defaults;
  104. $config->set('perimeters', 3);
  105. $config->set('cooling', 0); # prevent speed alteration
  106. $config->set('first_layer_speed', '100%'); # prevent speed alteration
  107. $config->set('layer_height', 0.4);
  108. $config->set('first_layer_height', '100%');
  109. $config->set('bottom_solid_layers', 3);
  110. $config->set('top_solid_layers', 3);
  111. $config->set('solid_infill_speed', 99);
  112. $config->set('top_solid_infill_speed', 99);
  113. my $print = Slic3r::Test::init_print('sloping_hole', config => $config);
  114. my %solid_layers = (); # Z => 1
  115. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  116. my ($self, $cmd, $args, $info) = @_;
  117. $solid_layers{$self->Z} = 1
  118. if $info->{extruding} && ($args->{F} // $self->F) == $config->solid_infill_speed*60;
  119. });
  120. is scalar(keys %solid_layers), $config->bottom_solid_layers + $config->top_solid_layers,
  121. "no superfluous shells are generated";
  122. }
  123. {
  124. my $config = Slic3r::Config->new_from_defaults;
  125. $config->set('spiral_vase', 1);
  126. $config->set('bottom_solid_layers', 0);
  127. $config->set('skirts', 0);
  128. $config->set('first_layer_height', '100%');
  129. # TODO: this needs to be tested with a model with sloping edges, where starting
  130. # points of each layer are not aligned - in that case we would test that no
  131. # travel moves are left to move to the new starting point - in a cube, end
  132. # points coincide with next layer starting points (provided there's no clipping)
  133. my $test = sub {
  134. my ($model_name, $description) = @_;
  135. my $print = Slic3r::Test::init_print($model_name, config => $config);
  136. my $travel_moves_after_first_extrusion = 0;
  137. my $started_extruding = 0;
  138. my @z_steps = ();
  139. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  140. my ($self, $cmd, $args, $info) = @_;
  141. $started_extruding = 1 if $info->{extruding};
  142. push @z_steps, ($args->{Z} - $self->Z)
  143. if $started_extruding && exists $args->{Z};
  144. $travel_moves_after_first_extrusion++
  145. if $info->{travel} && $started_extruding && !exists $args->{Z};
  146. });
  147. is $travel_moves_after_first_extrusion, 0, "no gaps in spiral vase ($description)";
  148. ok !(grep { $_ > $config->layer_height } @z_steps), "no gaps in Z ($description)";
  149. };
  150. $test->('20mm_cube', 'solid model');
  151. $test->('40x10', 'hollow model');
  152. $config->set('z_offset', -10);
  153. $test->('20mm_cube', 'solid model with negative z-offset');
  154. }
  155. __END__