skirt_brim.t 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. use Test::More tests => 8;
  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('skirts', 0);
  78. $config->set('brim_width', 5);
  79. $config->set('perimeter_extruder', 2);
  80. $config->set('support_material_extruder', 3);
  81. my $test = sub {
  82. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  83. my $tool = undef;
  84. my $brim_tool = undef;
  85. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  86. my ($self, $cmd, $args, $info) = @_;
  87. if ($cmd =~ /^T(\d+)/) {
  88. $tool = $1;
  89. } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
  90. if (!defined $brim_tool) {
  91. # first extrusion is brim
  92. $brim_tool = $tool;
  93. }
  94. }
  95. });
  96. return $brim_tool;
  97. };
  98. is $test->(), $config->perimeter_extruder-1,
  99. 'brim is printed with the extruder used for the perimeters of first object';
  100. $config->set('raft_layers', 1);
  101. is $test->(), $config->support_material_extruder-1,
  102. 'if raft is enabled, brim is printed with the extruder used for it';
  103. }
  104. {
  105. my $config = Slic3r::Config->new_from_defaults;
  106. $config->set('layer_height', 0.4);
  107. $config->set('first_layer_height', 0.4);
  108. $config->set('skirts', 1);
  109. $config->set('skirt_distance', 0);
  110. $config->set('support_material_speed', 99);
  111. $config->set('perimeter_extruder', 1);
  112. $config->set('support_material_extruder', 2);
  113. $config->set('cooling', 0); # to prevent speeds to be altered
  114. $config->set('first_layer_speed', '100%'); # to prevent speeds to be altered
  115. my $print = Slic3r::Test::init_print('overhang', config => $config);
  116. $print->process;
  117. # we enable support material after skirt has been generated
  118. $config->set('support_material', 1);
  119. $print->apply_config($config);
  120. my $skirt_length = 0;
  121. my @extrusion_points = ();
  122. my $tool = undef;
  123. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  124. my ($self, $cmd, $args, $info) = @_;
  125. if ($cmd =~ /^T(\d+)/) {
  126. $tool = $1;
  127. } elsif (defined $self->Z && $self->Z == $config->first_layer_height) {
  128. # we're on first layer
  129. if ($info->{extruding} && $info->{dist_XY} > 0) {
  130. my $speed = ($args->{F} // $self->F) / 60;
  131. if ($speed == $config->support_material_speed && $tool == $config->perimeter_extruder-1) {
  132. # skirt uses support material speed but first object's extruder
  133. $skirt_length += $info->{dist_XY};
  134. } else {
  135. push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
  136. }
  137. }
  138. }
  139. });
  140. my $convex_hull = convex_hull(\@extrusion_points);
  141. my $hull_perimeter = unscale($convex_hull->split_at_first_point->length);
  142. ok $skirt_length > $hull_perimeter, 'skirt length is large enough to contain object with support';
  143. }
  144. {
  145. my $config = Slic3r::Config->new_from_defaults;
  146. $config->set('min_skirt_length', 20);
  147. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  148. ok Slic3r::Test::gcode($print), 'no crash when using min_skirt_length';
  149. }
  150. __END__