PrusaSlicer-NonPlainar/lib/Slic3r/Format/STL.pm

42 lines
972 B
Perl
Raw Normal View History

package Slic3r::Format::STL;
use Moo;
2011-09-01 19:06:28 +00:00
use File::Basename qw(basename);
sub read_file {
my $self = shift;
my ($file) = @_;
my $path = Slic3r::encode_path($file);
die "Failed to open $file\n" if !-e $path;
my $mesh = Slic3r::TriangleMesh->new;
$mesh->ReadSTLFile($path);
$mesh->repair;
2012-02-17 12:49:33 +00:00
die "This STL file couldn't be read because it's empty.\n"
if $mesh->facets_count == 0;
my $model = Slic3r::Model->new;
my $basename = basename($file);
my $object = $model->add_object(input_file => $file, name => $basename);
my $volume = $object->add_volume(mesh => $mesh, name => $basename);
return $model;
}
sub write_file {
my $self = shift;
2014-04-25 08:20:30 +00:00
my ($file, $mesh, %params) = @_;
$mesh = $mesh->mesh if $mesh->isa('Slic3r::Model');
my $path = Slic3r::encode_path($file);
$params{binary}
2014-04-25 08:20:30 +00:00
? $mesh->write_binary($path)
: $mesh->write_ascii($path);
}
2011-09-01 19:06:28 +00:00
1;