2
# This script splits a STL plate into individual files
9
use lib "$FindBin::Bin/../lib";
12
use File::Basename qw(basename);
13
use Getopt::Long qw(:config no_auto_abbrev);
20
'help' => sub { usage() },
21
'ascii' => \$opt{ascii},
23
GetOptions(%options) or usage(1);
28
my $model = Slic3r::Format::STL->read_file($ARGV[0]);
29
my $basename = $ARGV[0];
30
$basename =~ s/\.stl$//i;
33
foreach my $new_mesh ($model->mesh->split_mesh) {
34
my $new_model = Slic3r::Model->new;
36
->add_object(vertices => $new_mesh->vertices)
37
->add_volume(facets => $new_mesh->facets);
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});
50
Usage: split_stl.pl [ OPTIONS ] file.stl
52
--help Output this usage screen and exit
53
--ascii Generate ASCII STL files (default: binary)
56
exit ($exit_code || 0);