From a776cf280bbebca69f089922e4851fac071771e1 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 3 Aug 2014 16:08:04 +0200 Subject: [PATCH] New --split option --- README.md | 1 + slic3r.pl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 31a997c84..9b8522125 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ The author of the Silk icon set is Mark James. --repair Repair given STL files and save them as _fixed.obj --cut Cut given input files at given Z (relative) and export them as _upper.stl and _lower.stl + --split Split the shells contained in given STL file into several STL files --info Output information about the supplied file(s) and exit -j, --threads Number of threads to use (1+, default: 2) diff --git a/slic3r.pl b/slic3r.pl index e5c19cc74..a34104a1d 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -8,6 +8,7 @@ BEGIN { use lib "$FindBin::Bin/lib"; } +use File::Basename qw(basename); use Getopt::Long qw(:config no_auto_abbrev); use List::Util qw(first); use POSIX qw(setlocale LC_NUMERIC); @@ -37,6 +38,7 @@ my %cli_options = (); 'merge|m' => \$opt{merge}, 'repair' => \$opt{repair}, 'cut=f' => \$opt{cut}, + 'split' => \$opt{split}, 'info' => \$opt{info}, 'scale=f' => \$opt{scale}, @@ -141,6 +143,23 @@ if (@ARGV) { # slicing from command line exit; } + if ($opt{split}) { + foreach my $file (@ARGV) { + my $model = Slic3r::Model->read_from_file($file); + $model->add_default_instances; + my $mesh = $model->mesh; + $mesh->repair; + + my $part_count = 0; + foreach my $new_mesh (@{$mesh->split}) { + my $output_file = sprintf '%s_%02d.stl', $file, ++$part_count; + printf "Writing to %s\n", basename($output_file); + Slic3r::Format::STL->write_file($output_file, $new_mesh, binary => 1); + } + } + exit; + } + while (my $input_file = shift @ARGV) { my $model; if ($opt{merge}) { @@ -232,6 +251,7 @@ Usage: slic3r.pl [ OPTIONS ] [ file.stl ] [ file2.stl ] ... --repair Repair given STL files and save them as _fixed.obj --cut Cut given input files at given Z (relative) and export them as _upper.stl and _lower.stl + --split Split the shells contained in given STL file into several STL files --info Output information about the supplied file(s) and exit $j