2012-02-25 17:35:25 +01:00
|
|
|
package Slic3r::Format::STL;
|
2011-09-06 11:50:43 +02:00
|
|
|
use Moo;
|
2011-09-01 21:06:28 +02:00
|
|
|
|
2011-10-12 10:47:26 +02:00
|
|
|
sub read_file {
|
|
|
|
my $self = shift;
|
|
|
|
my ($file) = @_;
|
|
|
|
|
2013-09-11 09:49:28 +02:00
|
|
|
my $mesh = Slic3r::TriangleMesh->new;
|
|
|
|
$mesh->ReadSTLFile(Slic3r::encode_path($file));
|
|
|
|
$mesh->repair;
|
2012-02-17 13:49:33 +01:00
|
|
|
|
2012-08-29 16:49:38 +02:00
|
|
|
my $model = Slic3r::Model->new;
|
2013-09-11 09:49:28 +02:00
|
|
|
my $object = $model->add_object;
|
|
|
|
my $volume = $object->add_volume(mesh => $mesh);
|
2012-08-29 16:49:38 +02:00
|
|
|
return $model;
|
2011-10-12 10:47:26 +02:00
|
|
|
}
|
|
|
|
|
2012-01-28 15:05:42 +01:00
|
|
|
sub write_file {
|
|
|
|
my $self = shift;
|
2012-08-29 16:49:38 +02:00
|
|
|
my ($file, $model, %params) = @_;
|
2012-01-28 15:05:42 +01:00
|
|
|
|
2013-09-11 09:49:28 +02:00
|
|
|
my $path = Slic3r::encode_path($file);
|
2012-01-28 15:05:42 +01:00
|
|
|
|
2012-08-29 16:49:38 +02:00
|
|
|
$params{binary}
|
2013-09-11 09:49:28 +02:00
|
|
|
? $model->mesh->write_binary($path)
|
|
|
|
: $model->mesh->write_ascii($path);
|
2012-02-19 15:45:27 +01:00
|
|
|
}
|
|
|
|
|
2011-09-01 21:06:28 +02:00
|
|
|
1;
|