wireframe.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/perl
  2. # This script exports experimental G-code for wireframe printing
  3. # (inspired by the brilliant WirePrint concept)
  4. use strict;
  5. use warnings;
  6. BEGIN {
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. }
  10. use Getopt::Long qw(:config no_auto_abbrev);
  11. use PDF::API2;
  12. use Slic3r;
  13. use Slic3r::ExtrusionPath ':roles';
  14. use Slic3r::Geometry qw(scale unscale X Y);
  15. my %opt = (
  16. step_height => 10,
  17. );
  18. {
  19. my %options = (
  20. 'help' => sub { usage() },
  21. 'output|o=s' => \$opt{output_file},
  22. 'step-height|h=f' => \$opt{step_height},
  23. 'nozzle-angle|a=f' => \$opt{nozzle_angle},
  24. );
  25. GetOptions(%options) or usage(1);
  26. $opt{output_file} or usage(1);
  27. ### Input file is not needed until we use hard-coded geometry:
  28. ### $ARGV[0] or usage(1);
  29. }
  30. {
  31. my $flow = Slic3r::Flow->new(
  32. width => 0.35,
  33. height => 0.35,
  34. nozzle_diameter => 0.35,
  35. bridge => 1,
  36. );
  37. my $section;
  38. # build a square section
  39. {
  40. my $dist = 2 * $opt{step_height}; # horizontal step
  41. my $side_modules = 3;
  42. my @points = (
  43. [0,0],
  44. (map [$_*$dist, 0], 1..$side_modules),
  45. (map [$side_modules*$dist, $_*$dist], 1..$side_modules),
  46. (map [($_-1)*$dist, $side_modules*$dist], reverse 1..$side_modules),
  47. (map [0, ($_-1)*$dist], reverse 1..$side_modules),
  48. );
  49. pop @points; # prevent coinciding endpoints
  50. $section = Slic3r::Polygon->new_scale(@points);
  51. }
  52. my $section_loop = Slic3r::ExtrusionLoop->new_from_paths(
  53. Slic3r::ExtrusionPath->new(
  54. polyline => $section->split_at_first_point,
  55. role => EXTR_ROLE_BRIDGE,
  56. mm3_per_mm => $flow->mm3_per_mm,
  57. width => $flow->width,
  58. height => $flow->height,
  59. )
  60. );
  61. my $vertical_steps = 3;
  62. open my $fh, '>', $opt{output_file};
  63. my $gcodegen = Slic3r::GCode->new(
  64. enable_loop_clipping => 0, # better bonding
  65. );
  66. $gcodegen->set_extruders([0]);
  67. print $fh $gcodegen->set_extruder(0);
  68. print $fh $gcodegen->writer->preamble;
  69. foreach my $z (map $_*$opt{step_height}, 0..($vertical_steps-1)) {
  70. print $fh $gcodegen->writer->travel_to_z($z + $flow->height);
  71. print $fh $gcodegen->extrude_loop($section_loop, "contour");
  72. }
  73. close $fh;
  74. }
  75. sub usage {
  76. my ($exit_code) = @_;
  77. print <<"EOF";
  78. Usage: wireframe.pl [ OPTIONS ] file.stl
  79. --help Output this usage screen and exit
  80. --output, -o Write to the specified file
  81. --step-height, -h Use the specified step height
  82. --nozzle-angle, -a Max nozzle angle
  83. EOF
  84. exit ($exit_code || 0);
  85. }
  86. __END__