From 6ae766600657cac98bf3b129fefd28ea33c8cda1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 8 Jun 2013 20:02:21 +0200 Subject: [PATCH] New utility script to dump STL contents in Perl syntax for writing tests --- utils/dump-stl.pl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 utils/dump-stl.pl diff --git a/utils/dump-stl.pl b/utils/dump-stl.pl new file mode 100644 index 000000000..a5c716b83 --- /dev/null +++ b/utils/dump-stl.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl +# This script dumps a STL file into Perl syntax for writing tests + +use strict; +use warnings; + +BEGIN { + use FindBin; + use lib "$FindBin::Bin/../lib"; +} + +use Slic3r; +$|++; + +$ARGV[0] or usage(1); + +{ + 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}; +} + + +sub usage { + my ($exit_code) = @_; + + print <<"EOF"; +Usage: dump-stl.pl file.stl +EOF + exit ($exit_code || 0); +} + +__END__