support.t 11 KB

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