Extend utils/dump-stl.pl to also write STL files

grow-support
Alessandro Ranellucci 2013-07-26 19:25:15 +02:00
parent f69dc7201d
commit 0a8872ca6c
2 changed files with 14 additions and 1 deletions

View File

@ -55,6 +55,8 @@ sub model {
$facets = [
[0,1,2],[2,3,4],[2,5,0],[4,6,2],[2,6,5],[2,1,3],[7,8,9],[10,9,8],[11,9,10],[12,9,11],[9,13,14],[7,15,16],[10,17,0],[10,0,5],[12,11,6],[18,16,0],[6,19,13],[6,13,9],[9,12,6],[17,18,0],[11,10,5],[11,5,6],[14,16,15],[17,7,18],[16,18,7],[14,15,9],[7,9,15],[7,17,8],[10,8,17],[20,21,22],[23,24,25],[26,23,27],[28,27,23],[29,28,23],[30,29,23],[25,31,32],[22,33,34],[35,36,37],[24,38,39],[21,40,41],[38,42,20],[33,43,44],[6,4,23],[6,23,25],[36,35,1],[1,0,38],[1,38,36],[29,30,4],[25,32,6],[40,42,0],[35,45,1],[4,3,28],[4,28,29],[3,1,45],[3,45,28],[22,34,19],[19,6,32],[19,32,22],[42,38,0],[30,23,4],[0,16,43],[0,43,40],[24,37,36],[38,24,36],[24,23,37],[37,23,26],[22,32,20],[20,32,31],[33,41,40],[43,33,40],[45,35,26],[37,26,35],[33,44,34],[44,43,46],[20,42,21],[40,21,42],[31,39,38],[20,31,38],[33,22,41],[21,41,22],[31,25,39],[24,39,25],[26,27,45],[28,45,27],[47,48,49],[47,50,48],[51,48,50],[52,48,51],[53,48,52],[54,55,56],[57,55,54],[58,55,57],[49,59,47],[60,56,55],[59,56,60],[60,47,59],[48,53,16],[56,13,19],[54,56,19],[56,59,13],[59,49,14],[59,14,13],[49,48,16],[49,16,14],[44,46,60],[44,60,55],[51,50,43],[19,34,58],[19,58,57],[53,52,16],[43,16,52],[43,52,51],[57,54,19],[47,60,46],[55,58,34],[55,34,44],[50,47,46],[50,46,43]
],
} else {
return undef;
}
my $mesh = Slic3r::TriangleMesh->new(

View File

@ -1,5 +1,6 @@
#!/usr/bin/perl
# This script dumps a STL file into Perl syntax for writing tests
# or dumps a test model into a STL file
use strict;
use warnings;
@ -10,15 +11,24 @@ BEGIN {
}
use Slic3r;
use Slic3r::Test;
$|++;
$ARGV[0] or usage(1);
{
if (-e $ARGV[0]) {
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};
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";
}
@ -27,6 +37,7 @@ sub usage {
print <<"EOF";
Usage: dump-stl.pl file.stl
dump-stl.pl modelname file.stl
EOF
exit ($exit_code || 0);
}