~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to utils/split_stl.pl

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# This script splits a STL plate into individual files
 
3
 
 
4
use strict;
 
5
use warnings;
 
6
 
 
7
BEGIN {
 
8
    use FindBin;
 
9
    use lib "$FindBin::Bin/../lib";
 
10
}
 
11
 
 
12
use File::Basename qw(basename);
 
13
use Getopt::Long qw(:config no_auto_abbrev);
 
14
use Slic3r;
 
15
$|++;
 
16
 
 
17
my %opt = ();
 
18
{
 
19
    my %options = (
 
20
        'help'                  => sub { usage() },
 
21
        'ascii'                 => \$opt{ascii},
 
22
    );
 
23
    GetOptions(%options) or usage(1);
 
24
    $ARGV[0] or usage(1);
 
25
}
 
26
 
 
27
{
 
28
    my $model = Slic3r::Format::STL->read_file($ARGV[0]);
 
29
    my $basename = $ARGV[0];
 
30
    $basename =~ s/\.stl$//i;
 
31
    
 
32
    my $part_count = 0;
 
33
    foreach my $new_mesh ($model->mesh->split_mesh) {
 
34
        my $new_model = Slic3r::Model->new;
 
35
        $new_model
 
36
            ->add_object(vertices   => $new_mesh->vertices)
 
37
            ->add_volume(facets     => $new_mesh->facets);
 
38
        
 
39
        my $output_file = sprintf '%s_%02d.stl', $basename, ++$part_count;
 
40
        printf "Writing to %s\n", basename($output_file);
 
41
        Slic3r::Format::STL->write_file($output_file, $new_model, binary => !$opt{ascii});
 
42
    }
 
43
}
 
44
 
 
45
 
 
46
sub usage {
 
47
    my ($exit_code) = @_;
 
48
    
 
49
    print <<"EOF";
 
50
Usage: split_stl.pl [ OPTIONS ] file.stl
 
51
 
 
52
    --help              Output this usage screen and exit
 
53
    --ascii             Generate ASCII STL files (default: binary)
 
54
    
 
55
EOF
 
56
    exit ($exit_code || 0);
 
57
}
 
58
 
 
59
__END__