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