Files
OrcaSlicer-bambulab/lib/Slic3r/Format/STL.pm
T

40 lines
880 B
Perl
Raw Normal View History

package Slic3r::Format::STL;
use Moo;
2011-09-01 21:06:28 +02:00
2014-02-14 22:24:30 +01:00
use File::Basename qw(basename);
sub read_file {
my $self = shift;
my ($file) = @_;
2014-03-25 19:06:51 +01:00
my $path = Slic3r::encode_path($file);
die "Failed to open $file\n" if !-e $path;
my $mesh = Slic3r::TriangleMesh->new;
2014-03-25 19:06:51 +01:00
$mesh->ReadSTLFile($path);
$mesh->repair;
2012-02-17 13:49:33 +01:00
my $model = Slic3r::Model->new;
2014-02-14 22:24:30 +01:00
my $material_id = basename($file);
$model->set_material($material_id);
my $object = $model->add_object;
2014-02-14 22:24:30 +01:00
my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
return $model;
}
sub write_file {
my $self = shift;
2014-04-25 10:20:30 +02:00
my ($file, $mesh, %params) = @_;
$mesh = $mesh->mesh if $mesh->isa('Slic3r::Model');
my $path = Slic3r::encode_path($file);
$params{binary}
2014-04-25 10:20:30 +02:00
? $mesh->write_binary($path)
: $mesh->write_ascii($path);
2012-02-19 15:45:27 +01:00
}
2011-09-01 21:06:28 +02:00
1;