dump-stl.pl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. $|++;
  14. $ARGV[0] or usage(1);
  15. if (-e $ARGV[0]) {
  16. my $model = Slic3r::Model->read_from_file($ARGV[0]);
  17. $model->objects->[0]->add_instance(offset => Slic3r::Pointf->new(0,0));
  18. my $mesh = $model->mesh;
  19. $mesh->repair;
  20. printf "VERTICES = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->vertices};
  21. printf "FACETS = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->facets};
  22. exit 0;
  23. } elsif ((my $model = Slic3r::Test::model($ARGV[0]))) {
  24. $ARGV[1] or die "Missing writeable destination as second argument\n";
  25. $model->write_stl($ARGV[1]);
  26. printf "Model $ARGV[0] written to $ARGV[1]\n";
  27. exit 0;
  28. } else {
  29. die "No such model exists\n";
  30. }
  31. sub usage {
  32. my ($exit_code) = @_;
  33. print <<"EOF";
  34. Usage: dump-stl.pl file.stl
  35. dump-stl.pl modelname file.stl
  36. EOF
  37. exit ($exit_code || 0);
  38. }
  39. __END__