dump-stl.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl
  2. # This script dumps a STL file into Perl syntax for writing tests
  3. # or dumps a test model into a STL file
  4. use strict;
  5. use warnings;
  6. BEGIN {
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. use local::lib "$FindBin::Bin/../local-lib";
  10. }
  11. use Slic3r;
  12. use Slic3r::Test;
  13. use File::Basename qw(basename);
  14. $|++;
  15. $ARGV[0] or usage(1);
  16. if (-e $ARGV[0]) {
  17. my $model = Slic3r::Model->load_stl($ARGV[0], basename($ARGV[0]));
  18. $model->objects->[0]->add_instance(offset => Slic3r::Pointf->new(0,0));
  19. my $mesh = $model->mesh;
  20. $mesh->repair;
  21. printf "VERTICES = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->vertices};
  22. printf "FACETS = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->facets};
  23. exit 0;
  24. } elsif ((my $model = Slic3r::Test::model($ARGV[0]))) {
  25. $ARGV[1] or die "Missing writeable destination as second argument\n";
  26. $model->store_stl($ARGV[1], 1);
  27. printf "Model $ARGV[0] written to $ARGV[1]\n";
  28. exit 0;
  29. } else {
  30. die "No such model exists\n";
  31. }
  32. sub usage {
  33. my ($exit_code) = @_;
  34. print <<"EOF";
  35. Usage: dump-stl.pl file.stl
  36. dump-stl.pl modelname file.stl
  37. EOF
  38. exit ($exit_code || 0);
  39. }
  40. __END__