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;
|
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]) {
|
2013-06-08 18:02:21 +00:00
|
|
|
my $model = Slic3r::Format::STL->read_file($ARGV[0]);
|
|
|
|
my $mesh = $model->mesh;
|
|
|
|
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";
|
|
|
|
Slic3r::Format::STL->write_file($ARGV[1], $model);
|
|
|
|
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__
|