Using the C++ file loaders.

This commit is contained in:
bubnikv 2017-02-26 21:54:42 +01:00
parent 121b3c31d2
commit b7aeeb968b
4 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,7 @@
# extends C++ class Slic3r::Model # extends C++ class Slic3r::Model
package Slic3r::Model; package Slic3r::Model;
use File::Basename qw(basename);
use List::Util qw(first max any); use List::Util qw(first max any);
use Slic3r::Geometry qw(X Y Z move_points); use Slic3r::Geometry qw(X Y Z move_points);
@ -8,9 +9,10 @@ sub read_from_file {
my $class = shift; my $class = shift;
my ($input_file) = @_; my ($input_file) = @_;
my $model = $input_file =~ /\.stl$/i ? Slic3r::Format::STL->read_file($input_file) my $model = $input_file =~ /\.stl$/i ? Slic3r::Model->load_stl(Slic3r::encode_path($input_file), basename($input_file))
: $input_file =~ /\.obj$/i ? Slic3r::Format::OBJ->read_file($input_file) : $input_file =~ /\.obj$/i ? Slic3r::Model->load_obj(Slic3r::encode_path($input_file), basename($input_file))
: $input_file =~ /\.amf(\.xml)?$/i ? Slic3r::Format::AMF->read_file($input_file) : $input_file =~ /\.amf(\.xml)?$/i ? Slic3r::Model->load_amf(Slic3r::encode_path($input_file))
: $input_file =~ /\.prus$/i ? Slic3r::Model->load_prus(Slic3r::encode_path($input_file))
: die "Input file must have .stl, .obj or .amf(.xml) extension\n"; : die "Input file must have .stl, .obj or .amf(.xml) extension\n";
die "The supplied file couldn't be read because it's empty.\n" die "The supplied file couldn't be read because it's empty.\n"

View File

@ -12,12 +12,13 @@ BEGIN {
use Slic3r; use Slic3r;
use Slic3r::Test; use Slic3r::Test;
use File::Basename qw(basename);
$|++; $|++;
$ARGV[0] or usage(1); $ARGV[0] or usage(1);
if (-e $ARGV[0]) { if (-e $ARGV[0]) {
my $model = Slic3r::Format::STL->read_file($ARGV[0]); my $model = Slic3r::Model->load_stl(Slic3r::encode_path($ARGV[0]), basename($ARGV[0]));
$model->objects->[0]->add_instance(offset => Slic3r::Pointf->new(0,0)); $model->objects->[0]->add_instance(offset => Slic3r::Pointf->new(0,0));
my $mesh = $model->mesh; my $mesh = $model->mesh;
$mesh->repair; $mesh->repair;

View File

@ -25,7 +25,7 @@ my %opt = ();
} }
{ {
my $model = Slic3r::Format::STL->read_file($ARGV[0]); my $model = Slic3r::Model->load_stl(Slic3r::encode_path($ARGV[0]), basename($ARGV[0]));
my $basename = $ARGV[0]; my $basename = $ARGV[0];
$basename =~ s/\.stl$//i; $basename =~ s/\.stl$//i;

View File

@ -25,7 +25,7 @@ my %opt = ();
} }
{ {
my @models = map Slic3r::Format::STL->read_file($_), @ARGV; my @models = map Slic3r::Model->load_stl(Slic3r::encode_path($_), basename($_)), @ARGV;
my $output_file = $ARGV[0]; my $output_file = $ARGV[0];
$output_file =~ s/\.stl$/.amf.xml/i; $output_file =~ s/\.stl$/.amf.xml/i;