support.t 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan skip_all => 'temporarily disabled';
  5. plan tests => 27;
  6. BEGIN {
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. use local::lib "$FindBin::Bin/../local-lib";
  10. }
  11. use List::Util qw(first);
  12. use Slic3r;
  13. use Slic3r::Flow ':roles';
  14. use Slic3r::Geometry qw(epsilon scale);
  15. use Slic3r::Geometry::Clipper qw(diff);
  16. use Slic3r::Test;
  17. {
  18. my $config = Slic3r::Config::new_from_defaults;
  19. $config->set('support_material', 1);
  20. my @contact_z = my @top_z = ();
  21. my $test = sub {
  22. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  23. my $object_config = $print->print->objects->[0]->config;
  24. my $flow = Slic3r::Flow->new_from_width(
  25. width => $object_config->support_material_extrusion_width || $object_config->extrusion_width,
  26. role => FLOW_ROLE_SUPPORT_MATERIAL,
  27. nozzle_diameter => $print->config->nozzle_diameter->[$object_config->support_material_extruder-1] // $print->config->nozzle_diameter->[0],
  28. layer_height => $object_config->layer_height,
  29. );
  30. my $support = Slic3r::Print::SupportMaterial->new(
  31. object_config => $print->print->objects->[0]->config,
  32. print_config => $print->print->config,
  33. flow => $flow,
  34. interface_flow => $flow,
  35. first_layer_flow => $flow,
  36. );
  37. my $support_z = $support->support_layers_z($print->print->objects->[0], \@contact_z, \@top_z, $config->layer_height);
  38. my $expected_top_spacing = $support->contact_distance($config->layer_height, $config->nozzle_diameter->[0]);
  39. is $support_z->[0], $config->first_layer_height,
  40. 'first layer height is honored';
  41. is scalar(grep { $support_z->[$_]-$support_z->[$_-1] <= 0 } 1..$#$support_z), 0,
  42. 'no null or negative support layers';
  43. is scalar(grep { $support_z->[$_]-$support_z->[$_-1] > $config->nozzle_diameter->[0] + epsilon } 1..$#$support_z), 0,
  44. 'no layers thicker than nozzle diameter';
  45. my $wrong_top_spacing = 0;
  46. foreach my $top_z (@top_z) {
  47. # find layer index of this top surface
  48. my $layer_id = first { abs($support_z->[$_] - $top_z) < epsilon } 0..$#$support_z;
  49. # check that first support layer above this top surface (or the next one) is spaced with nozzle diameter
  50. $wrong_top_spacing = 1
  51. if ($support_z->[$layer_id+1] - $support_z->[$layer_id]) != $expected_top_spacing
  52. && ($support_z->[$layer_id+2] - $support_z->[$layer_id]) != $expected_top_spacing;
  53. }
  54. ok !$wrong_top_spacing, 'layers above top surfaces are spaced correctly';
  55. };
  56. $config->set('layer_height', 0.2);
  57. $config->set('first_layer_height', 0.3);
  58. @contact_z = (1.9);
  59. @top_z = (1.1);
  60. $test->();
  61. $config->set('first_layer_height', 0.4);
  62. $test->();
  63. $config->set('layer_height', $config->nozzle_diameter->[0]);
  64. $test->();
  65. }
  66. {
  67. my $config = Slic3r::Config::new_from_defaults;
  68. $config->set('raft_layers', 3);
  69. $config->set('brim_width', 0);
  70. $config->set('skirts', 0);
  71. $config->set('support_material_extruder', 2);
  72. $config->set('support_material_interface_extruder', 2);
  73. $config->set('layer_height', 0.4);
  74. $config->set('first_layer_height', 0.4);
  75. my $print = Slic3r::Test::init_print('overhang', config => $config);
  76. ok my $gcode = Slic3r::Test::gcode($print), 'no conflict between raft/support and brim';
  77. my $tool = 0;
  78. Slic3r::GCode::Reader->new->parse($gcode, sub {
  79. my ($self, $cmd, $args, $info) = @_;
  80. if ($cmd =~ /^T(\d+)/) {
  81. $tool = $1;
  82. } elsif ($info->{extruding}) {
  83. if ($self->Z <= ($config->raft_layers * $config->layer_height)) {
  84. fail 'not extruding raft with support material extruder'
  85. if $tool != ($config->support_material_extruder-1);
  86. } else {
  87. fail 'support material exceeds raft layers'
  88. if $tool == $config->support_material_extruder-1;
  89. # TODO: we should test that full support is generated when we use raft too
  90. }
  91. }
  92. });
  93. }
  94. {
  95. my $config = Slic3r::Config::new_from_defaults;
  96. $config->set('skirts', 0);
  97. $config->set('raft_layers', 3);
  98. $config->set('support_material_pattern', 'honeycomb');
  99. $config->set('support_material_extrusion_width', 0.6);
  100. $config->set('first_layer_extrusion_width', '100%');
  101. $config->set('bridge_speed', 99);
  102. $config->set('cooling', [ 0 ]); # prevent speed alteration
  103. $config->set('first_layer_speed', '100%'); # prevent speed alteration
  104. $config->set('start_gcode', ''); # prevent any unexpected Z move
  105. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  106. my $layer_id = -1; # so that first Z move sets this to 0
  107. my @raft = my @first_object_layer = ();
  108. my %first_object_layer_speeds = (); # F => 1
  109. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  110. my ($self, $cmd, $args, $info) = @_;
  111. if ($info->{extruding} && $info->{dist_XY} > 0) {
  112. if ($layer_id <= $config->raft_layers) {
  113. # this is a raft layer or the first object layer
  114. my $line = Slic3r::Line->new_scale([ $self->X, $self->Y ], [ $info->{new_X}, $info->{new_Y} ]);
  115. my @path = @{$line->grow(scale($config->support_material_extrusion_width/2))};
  116. if ($layer_id < $config->raft_layers) {
  117. # this is a raft layer
  118. push @raft, @path;
  119. } else {
  120. push @first_object_layer, @path;
  121. $first_object_layer_speeds{ $args->{F} // $self->F } = 1;
  122. }
  123. }
  124. } elsif ($cmd eq 'G1' && $info->{dist_Z} > 0) {
  125. $layer_id++;
  126. }
  127. });
  128. ok !@{diff(\@first_object_layer, \@raft)},
  129. 'first object layer is completely supported by raft';
  130. is scalar(keys %first_object_layer_speeds), 1,
  131. 'only one speed used in first object layer';
  132. ok +(keys %first_object_layer_speeds)[0] == $config->bridge_speed*60,
  133. 'bridge speed used in first object layer';
  134. }
  135. {
  136. my $config = Slic3r::Config::new_from_defaults;
  137. $config->set('skirts', 0);
  138. $config->set('layer_height', 0.35);
  139. $config->set('first_layer_height', 0.3);
  140. $config->set('nozzle_diameter', [0.5]);
  141. $config->set('support_material_extruder', 2);
  142. $config->set('support_material_interface_extruder', 2);
  143. my $test = sub {
  144. my ($raft_layers) = @_;
  145. $config->set('raft_layers', $raft_layers);
  146. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  147. my %raft_z = (); # z => 1
  148. my $tool = undef;
  149. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  150. my ($self, $cmd, $args, $info) = @_;
  151. if ($cmd =~ /^T(\d+)/) {
  152. $tool = $1;
  153. } elsif ($info->{extruding} && $info->{dist_XY} > 0) {
  154. if ($tool == $config->support_material_extruder-1) {
  155. $raft_z{$self->Z} = 1;
  156. }
  157. }
  158. });
  159. is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated';
  160. };
  161. $test->(2);
  162. $test->(70);
  163. $config->set('layer_height', 0.4);
  164. $config->set('first_layer_height', 0.35);
  165. $test->(3);
  166. $test->(70);
  167. }
  168. {
  169. my $config = Slic3r::Config::new_from_defaults;
  170. $config->set('brim_width', 0);
  171. $config->set('skirts', 0);
  172. $config->set('support_material', 1);
  173. $config->set('top_solid_layers', 0); # so that we don't have the internal bridge over infill
  174. $config->set('bridge_speed', 99);
  175. $config->set('cooling', [ 0 ]);
  176. $config->set('first_layer_speed', '100%');
  177. my $test = sub {
  178. my $print = Slic3r::Test::init_print('overhang', config => $config);
  179. my $has_bridge_speed = 0;
  180. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  181. my ($self, $cmd, $args, $info) = @_;
  182. if ($info->{extruding}) {
  183. if (($args->{F} // $self->F) == $config->bridge_speed*60) {
  184. $has_bridge_speed = 1;
  185. }
  186. }
  187. });
  188. return $has_bridge_speed;
  189. };
  190. $config->set('support_material_contact_distance', 0.2);
  191. ok $test->(), 'bridge speed is used when support_material_contact_distance > 0';
  192. $config->set('support_material_contact_distance', 0);
  193. ok !$test->(), 'bridge speed is not used when support_material_contact_distance == 0';
  194. $config->set('raft_layers', 5);
  195. $config->set('support_material_contact_distance', 0.2);
  196. ok $test->(), 'bridge speed is used when raft_layers > 0 and support_material_contact_distance > 0';
  197. $config->set('support_material_contact_distance', 0);
  198. ok !$test->(), 'bridge speed is not used when raft_layers > 0 and support_material_contact_distance == 0';
  199. }
  200. {
  201. my $config = Slic3r::Config::new_from_defaults;
  202. $config->set('skirts', 0);
  203. $config->set('start_gcode', '');
  204. $config->set('raft_layers', 8);
  205. $config->set('nozzle_diameter', [0.4, 1]);
  206. $config->set('layer_height', 0.1);
  207. $config->set('first_layer_height', 0.8);
  208. $config->set('support_material_extruder', 2);
  209. $config->set('support_material_interface_extruder', 2);
  210. $config->set('support_material_contact_distance', 0);
  211. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  212. ok my $gcode = Slic3r::Test::gcode($print), 'first_layer_height is validated with support material extruder nozzle diameter when using raft layers';
  213. my $tool = undef;
  214. my @z = (0);
  215. my %layer_heights_by_tool = (); # tool => [ lh, lh... ]
  216. Slic3r::GCode::Reader->new->parse($gcode, sub {
  217. my ($self, $cmd, $args, $info) = @_;
  218. if ($cmd =~ /^T(\d+)/) {
  219. $tool = $1;
  220. } elsif ($cmd eq 'G1' && exists $args->{Z} && $args->{Z} != $self->Z) {
  221. push @z, $args->{Z};
  222. } elsif ($info->{extruding} && $info->{dist_XY} > 0) {
  223. $layer_heights_by_tool{$tool} ||= [];
  224. push @{ $layer_heights_by_tool{$tool} }, $z[-1] - $z[-2];
  225. }
  226. });
  227. ok !defined(first { $_ > $config->nozzle_diameter->[0] + epsilon }
  228. @{ $layer_heights_by_tool{$config->perimeter_extruder-1} }),
  229. 'no object layer is thicker than nozzle diameter';
  230. ok !defined(first { abs($_ - $config->layer_height) < epsilon }
  231. @{ $layer_heights_by_tool{$config->support_material_extruder-1} }),
  232. 'no support material layer is as thin as object layers';
  233. }
  234. __END__