skirt_brim.t 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. use Test::More tests => 6;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use local::lib "$FindBin::Bin/../local-lib";
  8. }
  9. use List::Util qw(first);
  10. use Slic3r;
  11. use Slic3r::Geometry qw(unscale convex_hull);
  12. use Slic3r::Test;
  13. {
  14. my $config = Slic3r::Config::new_from_defaults;
  15. $config->set('skirts', 1);
  16. $config->set('skirt_height', 2);
  17. $config->set('perimeters', 0);
  18. $config->set('support_material_speed', 99);
  19. $config->set('cooling', [ 0 ]); # to prevent speeds to be altered
  20. $config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
  21. my $test = sub {
  22. my ($conf) = @_;
  23. $conf ||= $config;
  24. my $print = Slic3r::Test::init_print(['20mm_cube','20mm_cube'], config => $config);
  25. my %layers_with_skirt = (); # Z => $count
  26. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  27. my ($self, $cmd, $args, $info) = @_;
  28. if (defined $self->Z) {
  29. $layers_with_skirt{$self->Z} //= 0;
  30. $layers_with_skirt{$self->Z} = 1
  31. if $info->{extruding} && ($args->{F} // $self->F) == $config->support_material_speed*60;
  32. }
  33. });
  34. fail "wrong number of layers with skirt"
  35. unless (grep $_, values %layers_with_skirt) == $config->skirt_height;
  36. };
  37. ok $test->(), "skirt_height is honored when printing multiple objects too";
  38. }
  39. {
  40. my $config = Slic3r::Config::new_from_defaults;
  41. $config->set('skirts', 0);
  42. $config->set('perimeters', 0);
  43. $config->set('top_solid_layers', 0); # to prevent solid shells and their speeds
  44. $config->set('bottom_solid_layers', 0); # to prevent solid shells and their speeds
  45. $config->set('brim_width', 5);
  46. $config->set('support_material_speed', 99);
  47. $config->set('cooling', [ 0 ]); # to prevent speeds to be altered
  48. $config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
  49. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  50. my %layers_with_brim = (); # Z => $count
  51. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  52. my ($self, $cmd, $args, $info) = @_;
  53. if (defined $self->Z) {
  54. $layers_with_brim{$self->Z} //= 0;
  55. $layers_with_brim{$self->Z} = 1
  56. if $info->{extruding} && $info->{dist_XY} > 0 && ($args->{F} // $self->F) != $config->infill_speed*60;
  57. }
  58. });
  59. is scalar(grep $_, values %layers_with_brim), 1, "brim is generated";
  60. }
  61. {
  62. my $config = Slic3r::Config::new_from_defaults;
  63. $config->set('skirts', 1);
  64. $config->set('brim_width', 10);
  65. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  66. ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt is smaller than brim width';
  67. }
  68. {
  69. my $config = Slic3r::Config::new_from_defaults;
  70. $config->set('skirts', 1);
  71. $config->set('skirt_height', 0);
  72. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  73. ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt_height = 0 and skirts > 0';
  74. }
  75. {
  76. my $config = Slic3r::Config::new_from_defaults;
  77. $config->set('layer_height', 0.4);
  78. $config->set('first_layer_height', 0.4);
  79. $config->set('skirts', 1);
  80. $config->set('skirt_distance', 0);
  81. $config->set('support_material_speed', 99);
  82. $config->set('perimeter_extruder', 1);
  83. $config->set('support_material_extruder', 2);
  84. $config->set('cooling', [ 0 ]); # to prevent speeds to be altered
  85. $config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
  86. my $print = Slic3r::Test::init_print('overhang', config => $config);
  87. $print->process;
  88. # we enable support material after skirt has been generated
  89. $config->set('support_material', 1);
  90. $print->apply_config($config);
  91. my $skirt_length = 0;
  92. my @extrusion_points = ();
  93. my $tool = undef;
  94. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  95. my ($self, $cmd, $args, $info) = @_;
  96. if ($cmd =~ /^T(\d+)/) {
  97. $tool = $1;
  98. } elsif (defined $self->Z && $self->Z == $config->first_layer_height) {
  99. # we're on first layer
  100. if ($info->{extruding} && $info->{dist_XY} > 0) {
  101. my $speed = ($args->{F} // $self->F) / 60;
  102. if ($speed == $config->support_material_speed && $tool == $config->perimeter_extruder-1) {
  103. # skirt uses support material speed but first object's extruder
  104. $skirt_length += $info->{dist_XY};
  105. } else {
  106. push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
  107. }
  108. }
  109. }
  110. });
  111. my $convex_hull = convex_hull(\@extrusion_points);
  112. my $hull_perimeter = unscale($convex_hull->split_at_first_point->length);
  113. ok $skirt_length > $hull_perimeter, 'skirt lenght is large enough to contain object with support';
  114. }
  115. {
  116. my $config = Slic3r::Config::new_from_defaults;
  117. $config->set('min_skirt_length', 20);
  118. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  119. ok Slic3r::Test::gcode($print), 'no crash when using min_skirt_length';
  120. }
  121. __END__