multi.t 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. use Test::More tests => 13;
  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(scale convex_hull);
  12. use Slic3r::Geometry::Clipper qw(offset);
  13. use Slic3r::Test;
  14. {
  15. my $config = Slic3r::Config::new_from_defaults;
  16. $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
  17. $config->set('raft_layers', 2);
  18. $config->set('infill_extruder', 2);
  19. $config->set('solid_infill_extruder', 3);
  20. $config->set('support_material_extruder', 4);
  21. $config->set('ooze_prevention', 1);
  22. $config->set('extruder_offset', [ [0,0], [20,0], [0,20], [20,20] ]);
  23. $config->set('temperature', [200, 180, 170, 160]);
  24. $config->set('first_layer_temperature', [206, 186, 166, 156]);
  25. $config->set('toolchange_gcode', ';toolchange'); # test that it doesn't crash when this is supplied
  26. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  27. my $tool = undef;
  28. my @tool_temp = (0,0,0,0);
  29. my @toolchange_points = ();
  30. my @extrusion_points = ();
  31. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  32. my ($self, $cmd, $args, $info) = @_;
  33. if ($cmd =~ /^T(\d+)/) {
  34. # ignore initial toolchange
  35. if (defined $tool) {
  36. my $expected_temp = $self->Z == ($config->get_value('first_layer_height') + $config->z_offset)
  37. ? $config->first_layer_temperature->[$tool]
  38. : $config->temperature->[$tool];
  39. die 'standby temperature was not set before toolchange'
  40. if $tool_temp[$tool] != $expected_temp + $config->standby_temperature_delta;
  41. push @toolchange_points, my $point = Slic3r::Point->new_scale($self->X, $self->Y);
  42. }
  43. $tool = $1;
  44. } elsif ($cmd eq 'M104' || $cmd eq 'M109') {
  45. my $t = $args->{T} // $tool;
  46. if ($tool_temp[$t] == 0) {
  47. fail 'initial temperature is not equal to first layer temperature + standby delta'
  48. unless $args->{S} == $config->first_layer_temperature->[$t] + $config->standby_temperature_delta;
  49. }
  50. $tool_temp[$t] = $args->{S};
  51. } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
  52. push @extrusion_points, my $point = Slic3r::Point->new_scale($args->{X}, $args->{Y});
  53. $point->translate(map +scale($_), @{ $config->extruder_offset->[$tool] });
  54. }
  55. });
  56. my $convex_hull = convex_hull(\@extrusion_points);
  57. my @t = ();
  58. foreach my $point (@toolchange_points) {
  59. foreach my $offset (@{$config->extruder_offset}) {
  60. push @t, my $p = $point->clone;
  61. $p->translate(map +scale($_), @$offset);
  62. }
  63. }
  64. ok !(defined first { $convex_hull->contains_point($_) } @t), 'all nozzles are outside skirt at toolchange';
  65. if (0) {
  66. require "Slic3r/SVG.pm";
  67. Slic3r::SVG::output(
  68. "ooze_prevention_test.svg",
  69. no_arrows => 1,
  70. polygons => [$convex_hull],
  71. red_points => \@t,
  72. points => \@toolchange_points,
  73. );
  74. }
  75. # offset the skirt by the maximum displacement between extruders plus a safety extra margin
  76. my $delta = scale(20 * sqrt(2) + 1);
  77. my $outer_convex_hull = offset([$convex_hull], +$delta)->[0];
  78. ok !(defined first { !$outer_convex_hull->contains_point($_) } @toolchange_points), 'all toolchanges happen within expected area';
  79. }
  80. {
  81. my $config = Slic3r::Config::new_from_defaults;
  82. $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
  83. $config->set('support_material_extruder', 3);
  84. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  85. ok Slic3r::Test::gcode($print), 'no errors when using non-consecutive extruders';
  86. }
  87. {
  88. my $config = Slic3r::Config->new;
  89. $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
  90. $config->set('extruder', 2);
  91. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  92. like Slic3r::Test::gcode($print), qr/ T1/, 'extruder shortcut';
  93. }
  94. {
  95. my $config = Slic3r::Config->new;
  96. $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
  97. $config->set('perimeter_extruder', 2);
  98. $config->set('infill_extruder', 2);
  99. $config->set('support_material_extruder', 2);
  100. $config->set('support_material_interface_extruder', 2);
  101. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  102. ok Slic3r::Test::gcode($print), 'no errors when using multiple skirts with a single, non-zero, extruder';
  103. }
  104. {
  105. my $model = stacked_cubes();
  106. my $lower_config = $model->get_material('lower')->config;
  107. my $upper_config = $model->get_material('upper')->config;
  108. $lower_config->set('extruder', 1);
  109. $lower_config->set('bottom_solid_layers', 0);
  110. $lower_config->set('top_solid_layers', 1);
  111. $upper_config->set('extruder', 2);
  112. $upper_config->set('bottom_solid_layers', 1);
  113. $upper_config->set('top_solid_layers', 0);
  114. my $config = Slic3r::Config::new_from_defaults;
  115. $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
  116. $config->set('fill_density', 0);
  117. $config->set('solid_infill_speed', 99);
  118. $config->set('top_solid_infill_speed', 99);
  119. $config->set('cooling', [ 0 ]); # for preventing speeds from being altered
  120. $config->set('first_layer_speed', '100%'); # for preventing speeds from being altered
  121. my $test = sub {
  122. my $print = Slic3r::Test::init_print($model, config => $config);
  123. my $tool = undef;
  124. my %T0_shells = my %T1_shells = (); # Z => 1
  125. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  126. my ($self, $cmd, $args, $info) = @_;
  127. if ($cmd =~ /^T(\d+)/) {
  128. $tool = $1;
  129. } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
  130. if (($args->{F} // $self->F) == $config->solid_infill_speed*60) {
  131. if ($tool == 0) {
  132. $T0_shells{$self->Z} = 1;
  133. } elsif ($tool == 1) {
  134. $T1_shells{$self->Z} = 1;
  135. }
  136. }
  137. }
  138. });
  139. return [ sort keys %T0_shells ], [ sort keys %T1_shells ];
  140. };
  141. {
  142. my ($t0, $t1) = $test->();
  143. is scalar(@$t0), 0, 'no interface shells';
  144. is scalar(@$t1), 0, 'no interface shells';
  145. }
  146. {
  147. $config->set('interface_shells', 1);
  148. my ($t0, $t1) = $test->();
  149. is scalar(@$t0), $lower_config->top_solid_layers, 'top interface shells';
  150. is scalar(@$t1), $upper_config->bottom_solid_layers, 'bottom interface shells';
  151. }
  152. }
  153. {
  154. my $model = stacked_cubes();
  155. my $object = $model->objects->[0];
  156. my $config = Slic3r::Config::new_from_defaults;
  157. $config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
  158. $config->set('layer_height', 0.4);
  159. $config->set('first_layer_height', '100%');
  160. $config->set('skirts', 0);
  161. my $print = Slic3r::Test::init_print($model, config => $config);
  162. is $object->volumes->[0]->config->extruder, 1, 'auto_assign_extruders() assigned correct extruder to first volume';
  163. is $object->volumes->[1]->config->extruder, 2, 'auto_assign_extruders() assigned correct extruder to second volume';
  164. my $tool = undef;
  165. my %T0 = my %T1 = (); # Z => 1
  166. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  167. my ($self, $cmd, $args, $info) = @_;
  168. if ($cmd =~ /^T(\d+)/) {
  169. $tool = $1;
  170. } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) {
  171. if ($tool == 0) {
  172. $T0{$self->Z} = 1;
  173. } elsif ($tool == 1) {
  174. $T1{$self->Z} = 1;
  175. }
  176. }
  177. });
  178. ok !(defined first { $_ > 20 } keys %T0), 'T0 is never used for upper object';
  179. ok !(defined first { $_ < 20 } keys %T1), 'T1 is never used for lower object';
  180. }
  181. sub stacked_cubes {
  182. my $model = Slic3r::Model->new;
  183. my $object = $model->add_object;
  184. $object->add_volume(mesh => Slic3r::Test::mesh('20mm_cube'), material_id => 'lower');
  185. $object->add_volume(mesh => Slic3r::Test::mesh('20mm_cube', translate => [0,0,20]), material_id => 'upper');
  186. $object->add_instance(offset => Slic3r::Pointf->new(0,0));
  187. return $model;
  188. }
  189. __END__