2013-06-08 18:02:21 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# This script dumps a STL file into Perl syntax for writing tests
|
2013-07-26 17:25:15 +00:00
|
|
|
# or dumps a test model into a STL file
|
2013-06-08 18:02:21 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
|
|
|
}
|
|
|
|
|
|
|
|
use Slic3r;
|
2013-07-26 17:25:15 +00:00
|
|
|
use Slic3r::Test;
|
2017-02-26 20:54:42 +00:00
|
|
|
use File::Basename qw(basename);
|
2013-06-08 18:02:21 +00:00
|
|
|
$|++;
|
|
|
|
|
|
|
|
$ARGV[0] or usage(1);
|
|
|
|
|
2013-07-26 17:25:15 +00:00
|
|
|
if (-e $ARGV[0]) {
|
2017-08-03 15:31:31 +00:00
|
|
|
my $model = Slic3r::Model->load_stl($ARGV[0], basename($ARGV[0]));
|
2014-05-09 12:24:35 +00:00
|
|
|
$model->objects->[0]->add_instance(offset => Slic3r::Pointf->new(0,0));
|
2013-06-08 18:02:21 +00:00
|
|
|
my $mesh = $model->mesh;
|
2013-09-17 17:25:10 +00:00
|
|
|
$mesh->repair;
|
2013-06-08 18:02:21 +00:00
|
|
|
printf "VERTICES = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->vertices};
|
|
|
|
printf "FACETS = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->facets};
|
2013-07-26 17:25:15 +00:00
|
|
|
exit 0;
|
|
|
|
} elsif ((my $model = Slic3r::Test::model($ARGV[0]))) {
|
|
|
|
$ARGV[1] or die "Missing writeable destination as second argument\n";
|
2017-08-03 15:31:31 +00:00
|
|
|
$model->store_stl($ARGV[1], 1);
|
2013-07-26 17:25:15 +00:00
|
|
|
printf "Model $ARGV[0] written to $ARGV[1]\n";
|
|
|
|
exit 0;
|
|
|
|
} else {
|
|
|
|
die "No such model exists\n";
|
2013-06-08 18:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
my ($exit_code) = @_;
|
|
|
|
|
|
|
|
print <<"EOF";
|
|
|
|
Usage: dump-stl.pl file.stl
|
2013-07-26 17:25:15 +00:00
|
|
|
dump-stl.pl modelname file.stl
|
2013-06-08 18:02:21 +00:00
|
|
|
EOF
|
|
|
|
exit ($exit_code || 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__END__
|