2012-08-29 14:49:38 +00:00
|
|
|
|
package Slic3r::Model;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
use List::Util qw(first max);
|
|
|
|
|
use Slic3r::Geometry qw(X Y Z MIN move_points);
|
2012-08-29 14:49:38 +00:00
|
|
|
|
|
2012-08-29 16:23:34 +00:00
|
|
|
|
has 'materials' => (is => 'ro', default => sub { {} });
|
2012-08-29 14:49:38 +00:00
|
|
|
|
has 'objects' => (is => 'ro', default => sub { [] });
|
2013-06-22 17:36:50 +00:00
|
|
|
|
has '_bounding_box' => (is => 'rw');
|
2012-08-29 14:49:38 +00:00
|
|
|
|
|
2012-08-29 17:37:27 +00:00
|
|
|
|
sub read_from_file {
|
|
|
|
|
my $class = shift;
|
|
|
|
|
my ($input_file) = @_;
|
|
|
|
|
|
|
|
|
|
my $model = $input_file =~ /\.stl$/i ? Slic3r::Format::STL->read_file($input_file)
|
|
|
|
|
: $input_file =~ /\.obj$/i ? Slic3r::Format::OBJ->read_file($input_file)
|
|
|
|
|
: $input_file =~ /\.amf(\.xml)?$/i ? Slic3r::Format::AMF->read_file($input_file)
|
|
|
|
|
: die "Input file must have .stl, .obj or .amf(.xml) extension\n";
|
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
|
$_->input_file($input_file) for @{$model->objects};
|
2012-08-29 17:37:27 +00:00
|
|
|
|
return $model;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
sub merge {
|
|
|
|
|
my $class = shift;
|
|
|
|
|
my @models = @_;
|
|
|
|
|
|
2013-09-11 12:46:38 +00:00
|
|
|
|
my $new_model = ref($class)
|
|
|
|
|
? $class
|
|
|
|
|
: $class->new;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
foreach my $model (@models) {
|
|
|
|
|
# merge material attributes (should we rename them in case of duplicates?)
|
|
|
|
|
$new_model->set_material($_, { %{$model->materials->{$_}}, %{$model->materials->{$_} || {}} })
|
|
|
|
|
for keys %{$model->materials};
|
|
|
|
|
|
|
|
|
|
foreach my $object (@{$model->objects}) {
|
|
|
|
|
my $new_object = $new_model->add_object(
|
|
|
|
|
input_file => $object->input_file,
|
2013-08-25 12:37:50 +00:00
|
|
|
|
config => $object->config,
|
2013-05-18 14:48:26 +00:00
|
|
|
|
layer_height_ranges => $object->layer_height_ranges,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$new_object->add_volume(
|
|
|
|
|
material_id => $_->material_id,
|
2013-09-11 12:46:38 +00:00
|
|
|
|
mesh => $_->mesh->clone,
|
2013-05-18 14:48:26 +00:00
|
|
|
|
) for @{$object->volumes};
|
|
|
|
|
|
|
|
|
|
$new_object->add_instance(
|
|
|
|
|
offset => $_->offset,
|
|
|
|
|
rotation => $_->rotation,
|
|
|
|
|
) for @{ $object->instances // [] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $new_model;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 14:49:38 +00:00
|
|
|
|
sub add_object {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
my $object = Slic3r::Model::Object->new(model => $self, @_);
|
|
|
|
|
push @{$self->objects}, $object;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
$self->_bounding_box(undef);
|
2012-08-29 14:49:38 +00:00
|
|
|
|
return $object;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
|
sub set_material {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($material_id, $attributes) = @_;
|
|
|
|
|
|
2012-09-23 00:52:31 +00:00
|
|
|
|
return $self->materials->{$material_id} = Slic3r::Model::Region->new(
|
2012-09-22 17:04:36 +00:00
|
|
|
|
model => $self,
|
|
|
|
|
attributes => $attributes || {},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
sub arrange_objects {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($config) = @_;
|
|
|
|
|
|
|
|
|
|
# do we have objects with no position?
|
|
|
|
|
if (first { !defined $_->instances } @{$self->objects}) {
|
|
|
|
|
# we shall redefine positions for all objects
|
|
|
|
|
|
|
|
|
|
my ($copies, @positions) = $self->_arrange(
|
|
|
|
|
config => $config,
|
|
|
|
|
items => $self->objects,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# apply positions to objects
|
|
|
|
|
foreach my $object (@{$self->objects}) {
|
|
|
|
|
$object->align_to_origin;
|
|
|
|
|
|
|
|
|
|
$object->instances([]);
|
|
|
|
|
$object->add_instance(
|
|
|
|
|
offset => $_,
|
|
|
|
|
rotation => 0,
|
|
|
|
|
) for splice @positions, 0, $copies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
# we only have objects with defined position
|
|
|
|
|
|
|
|
|
|
# align the whole model to origin as it is
|
|
|
|
|
$self->align_to_origin;
|
|
|
|
|
|
|
|
|
|
# arrange this model as a whole
|
|
|
|
|
my ($copies, @positions) = $self->_arrange(
|
|
|
|
|
config => $config,
|
|
|
|
|
items => [$self],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# apply positions to objects by translating the current positions
|
|
|
|
|
foreach my $object (@{$self->objects}) {
|
|
|
|
|
my @old_instances = @{$object->instances};
|
|
|
|
|
$object->instances([]);
|
|
|
|
|
foreach my $instance (@old_instances) {
|
|
|
|
|
$object->add_instance(
|
|
|
|
|
offset => $_,
|
|
|
|
|
rotation => $instance->rotation,
|
2013-06-13 12:33:10 +00:00
|
|
|
|
scaling_factor => $instance->scaling_factor,
|
2013-05-18 14:48:26 +00:00
|
|
|
|
) for move_points($instance->offset, @positions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub _arrange {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my %params = @_;
|
|
|
|
|
|
|
|
|
|
my $config = $params{config};
|
|
|
|
|
my @items = @{$params{items}}; # can be Model or Object objects, they have to implement size()
|
|
|
|
|
|
|
|
|
|
if ($config->duplicate_grid->[X] > 1 || $config->duplicate_grid->[Y] > 1) {
|
|
|
|
|
if (@items > 1) {
|
|
|
|
|
die "Grid duplication is not supported with multiple objects\n";
|
|
|
|
|
}
|
|
|
|
|
my @positions = ();
|
|
|
|
|
my $size = $items[0]->size;
|
|
|
|
|
my $dist = $config->duplicate_distance;
|
|
|
|
|
for my $x_copy (1..$config->duplicate_grid->[X]) {
|
|
|
|
|
for my $y_copy (1..$config->duplicate_grid->[Y]) {
|
|
|
|
|
push @positions, [
|
|
|
|
|
($size->[X] + $dist) * ($x_copy-1),
|
|
|
|
|
($size->[Y] + $dist) * ($y_copy-1),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ($config->duplicate_grid->[X] * $config->duplicate_grid->[Y]), @positions;
|
|
|
|
|
} else {
|
|
|
|
|
my $total_parts = $config->duplicate * @items;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
my @sizes = map $_->size, @items;
|
|
|
|
|
my $partx = max(map $_->[X], @sizes);
|
|
|
|
|
my $party = max(map $_->[Y], @sizes);
|
2013-05-18 14:48:26 +00:00
|
|
|
|
return $config->duplicate,
|
|
|
|
|
Slic3r::Geometry::arrange
|
|
|
|
|
($total_parts, $partx, $party, (map $_, @{$config->bed_size}),
|
|
|
|
|
$config->min_object_distance, $config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub size {
|
|
|
|
|
my $self = shift;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
return $self->bounding_box->size;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:21:25 +00:00
|
|
|
|
sub bounding_box {
|
2013-05-18 14:48:26 +00:00
|
|
|
|
my $self = shift;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
|
|
|
|
|
if (!defined $self->_bounding_box) {
|
2013-09-11 09:55:08 +00:00
|
|
|
|
$self->_bounding_box(Slic3r::Geometry::BoundingBox->merge(map $_->bounding_box, @{$self->objects}));
|
2013-06-22 17:36:50 +00:00
|
|
|
|
}
|
2013-12-06 18:34:50 +00:00
|
|
|
|
return $self->_bounding_box->clone;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub align_to_origin {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
# calculate the displacements needed to
|
|
|
|
|
# have lowest value for each axis at coordinate 0
|
2013-06-02 14:56:08 +00:00
|
|
|
|
{
|
2013-06-16 10:21:25 +00:00
|
|
|
|
my $bb = $self->bounding_box;
|
|
|
|
|
$self->move(map -$bb->extents->[$_][MIN], X,Y,Z);
|
2013-06-02 14:56:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# align all instances to 0,0 as well
|
|
|
|
|
{
|
|
|
|
|
my @instances = map @{$_->instances}, @{$self->objects};
|
|
|
|
|
my @extents = Slic3r::Geometry::bounding_box_3D([ map $_->offset, @instances ]);
|
|
|
|
|
$_->offset->translate(-$extents[X][MIN], -$extents[Y][MIN]) for @instances;
|
|
|
|
|
}
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-22 17:36:50 +00:00
|
|
|
|
sub scale {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
$_->scale(@_) for @{$self->objects};
|
|
|
|
|
$self->_bounding_box->scale(@_) if defined $self->_bounding_box;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
sub move {
|
|
|
|
|
my $self = shift;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
my @shift = @_;
|
|
|
|
|
|
|
|
|
|
$_->move(@shift) for @{$self->objects};
|
|
|
|
|
$self->_bounding_box->translate(@shift) if defined $self->_bounding_box;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 14:49:38 +00:00
|
|
|
|
# flattens everything to a single mesh
|
|
|
|
|
sub mesh {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
2012-09-12 14:30:44 +00:00
|
|
|
|
my @meshes = ();
|
2012-08-29 14:49:38 +00:00
|
|
|
|
foreach my $object (@{$self->objects}) {
|
2012-09-12 14:30:44 +00:00
|
|
|
|
my @instances = $object->instances ? @{$object->instances} : (undef);
|
|
|
|
|
foreach my $instance (@instances) {
|
|
|
|
|
my $mesh = $object->mesh->clone;
|
|
|
|
|
if ($instance) {
|
2013-09-19 10:25:00 +00:00
|
|
|
|
$mesh->rotate($instance->rotation, Slic3r::Point->new(0,0));
|
2013-06-13 12:33:10 +00:00
|
|
|
|
$mesh->scale($instance->scaling_factor);
|
2012-09-12 14:30:44 +00:00
|
|
|
|
$mesh->align_to_origin;
|
2013-09-19 10:25:00 +00:00
|
|
|
|
$mesh->translate(@{$instance->offset}, 0);
|
2012-09-12 14:30:44 +00:00
|
|
|
|
}
|
|
|
|
|
push @meshes, $mesh;
|
|
|
|
|
}
|
2012-08-29 14:49:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 17:25:10 +00:00
|
|
|
|
my $mesh = Slic3r::TriangleMesh->new;
|
|
|
|
|
$mesh->merge($_) for @meshes;
|
|
|
|
|
return $mesh;
|
2012-08-29 14:49:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
# this method splits objects into multiple distinct objects by walking their meshes
|
|
|
|
|
sub split_meshes {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
my @objects = @{$self->objects};
|
|
|
|
|
@{$self->objects} = ();
|
|
|
|
|
|
|
|
|
|
foreach my $object (@objects) {
|
|
|
|
|
if (@{$object->volumes} > 1) {
|
|
|
|
|
# We can't split meshes if there's more than one material, because
|
|
|
|
|
# we can't group the resulting meshes by object afterwards
|
|
|
|
|
push @{$self->objects}, $object;
|
|
|
|
|
next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $volume = $object->volumes->[0];
|
2013-09-19 10:25:00 +00:00
|
|
|
|
foreach my $mesh (@{$volume->mesh->split}) {
|
2013-05-18 14:48:26 +00:00
|
|
|
|
my $new_object = $self->add_object(
|
|
|
|
|
input_file => $object->input_file,
|
2013-08-25 12:37:50 +00:00
|
|
|
|
config => $object->config,
|
2013-05-18 14:48:26 +00:00
|
|
|
|
layer_height_ranges => $object->layer_height_ranges,
|
|
|
|
|
);
|
|
|
|
|
$new_object->add_volume(
|
2013-09-19 10:25:00 +00:00
|
|
|
|
mesh => $mesh,
|
2013-05-18 14:48:26 +00:00
|
|
|
|
material_id => $volume->material_id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# let's now align the new object to the origin and put its displacement
|
|
|
|
|
# (extents) in the instances info
|
2013-06-16 10:21:25 +00:00
|
|
|
|
my $bb = $mesh->bounding_box;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
$new_object->align_to_origin;
|
|
|
|
|
|
|
|
|
|
# add one instance per original instance applying the displacement
|
|
|
|
|
$new_object->add_instance(
|
2013-06-16 10:21:25 +00:00
|
|
|
|
offset => [ $_->offset->[X] + $bb->x_min, $_->offset->[Y] + $bb->y_min ],
|
2013-05-18 14:48:26 +00:00
|
|
|
|
rotation => $_->rotation,
|
2013-06-13 12:33:10 +00:00
|
|
|
|
scaling_factor => $_->scaling_factor,
|
2013-05-18 14:48:26 +00:00
|
|
|
|
) for @{ $object->instances // [] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 13:10:11 +00:00
|
|
|
|
sub print_info {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
$_->print_info for @{$self->objects};
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 17:52:32 +00:00
|
|
|
|
sub get_material_name {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($material_id) = @_;
|
|
|
|
|
|
|
|
|
|
my $name;
|
|
|
|
|
if (exists $self->materials->{$material_id}) {
|
|
|
|
|
$name //= $self->materials->{$material_id}->attributes->{$_} for qw(Name name);
|
|
|
|
|
} elsif ($material_id eq '_') {
|
|
|
|
|
$name = 'Default material';
|
|
|
|
|
}
|
|
|
|
|
$name //= $material_id;
|
|
|
|
|
return $name;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-23 00:52:31 +00:00
|
|
|
|
package Slic3r::Model::Region;
|
2012-08-29 14:49:38 +00:00
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
|
|
has 'model' => (is => 'ro', weak_ref => 1, required => 1);
|
|
|
|
|
has 'attributes' => (is => 'rw', default => sub { {} });
|
|
|
|
|
|
|
|
|
|
package Slic3r::Model::Object;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
2013-07-31 13:10:11 +00:00
|
|
|
|
use File::Basename qw(basename);
|
2013-08-25 16:01:59 +00:00
|
|
|
|
use List::Util qw(first sum);
|
2013-06-13 12:33:10 +00:00
|
|
|
|
use Slic3r::Geometry qw(X Y Z MIN MAX move_points move_points_3D);
|
2013-05-14 14:31:50 +00:00
|
|
|
|
use Storable qw(dclone);
|
2012-09-11 16:11:46 +00:00
|
|
|
|
|
2012-09-12 14:30:44 +00:00
|
|
|
|
has 'input_file' => (is => 'rw');
|
2012-08-29 14:49:38 +00:00
|
|
|
|
has 'model' => (is => 'ro', weak_ref => 1, required => 1);
|
|
|
|
|
has 'volumes' => (is => 'ro', default => sub { [] });
|
2013-11-24 13:28:17 +00:00
|
|
|
|
has 'instances' => (is => 'rw'); # in unscaled coordinates
|
2013-08-25 12:37:50 +00:00
|
|
|
|
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new });
|
2013-03-10 13:58:49 +00:00
|
|
|
|
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
2013-12-09 00:12:37 +00:00
|
|
|
|
has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => region_idx }
|
2013-06-22 17:36:50 +00:00
|
|
|
|
has '_bounding_box' => (is => 'rw');
|
2012-08-29 14:49:38 +00:00
|
|
|
|
|
|
|
|
|
sub add_volume {
|
|
|
|
|
my $self = shift;
|
2012-09-23 12:48:58 +00:00
|
|
|
|
my %args = @_;
|
2012-08-29 14:49:38 +00:00
|
|
|
|
|
2013-09-11 07:49:28 +00:00
|
|
|
|
push @{$self->volumes}, my $volume = Slic3r::Model::Volume->new(
|
|
|
|
|
object => $self,
|
|
|
|
|
%args,
|
|
|
|
|
);
|
2013-06-22 17:36:50 +00:00
|
|
|
|
$self->_bounding_box(undef);
|
|
|
|
|
$self->model->_bounding_box(undef);
|
2012-08-29 14:49:38 +00:00
|
|
|
|
return $volume;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub add_instance {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
$self->instances([]) if !defined $self->instances;
|
|
|
|
|
push @{$self->instances}, Slic3r::Model::Instance->new(object => $self, @_);
|
2013-06-22 17:36:50 +00:00
|
|
|
|
$self->model->_bounding_box(undef);
|
2012-08-29 14:49:38 +00:00
|
|
|
|
return $self->instances->[-1];
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 17:37:27 +00:00
|
|
|
|
sub mesh {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
|
my $mesh = Slic3r::TriangleMesh->new;
|
2013-09-11 07:49:28 +00:00
|
|
|
|
$mesh->merge($_->mesh) for @{$self->volumes};
|
2013-09-09 22:40:46 +00:00
|
|
|
|
return $mesh;
|
2012-08-29 17:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
sub size {
|
|
|
|
|
my $self = shift;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
return $self->bounding_box->size;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-13 12:33:10 +00:00
|
|
|
|
sub center {
|
|
|
|
|
my $self = shift;
|
2013-06-16 10:21:25 +00:00
|
|
|
|
return $self->bounding_box->center;
|
2013-06-13 12:33:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
|
sub center_2D {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
return $self->bounding_box->center_2D;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-13 12:33:10 +00:00
|
|
|
|
sub bounding_box {
|
|
|
|
|
my $self = shift;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
|
|
|
|
|
if (!defined $self->_bounding_box) {
|
2013-09-11 09:55:08 +00:00
|
|
|
|
my @meshes = map $_->mesh, @{$self->volumes};
|
|
|
|
|
my $bounding_box = Slic3r::Geometry::BoundingBox->new_from_bb((shift @meshes)->bb3);
|
|
|
|
|
$bounding_box->merge(Slic3r::Geometry::BoundingBox->new_from_bb($_->bb3)) for @meshes;
|
|
|
|
|
$self->_bounding_box($bounding_box);
|
2013-06-22 17:36:50 +00:00
|
|
|
|
}
|
2013-12-06 18:34:50 +00:00
|
|
|
|
return $self->_bounding_box->clone;
|
2013-06-13 12:33:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
sub align_to_origin {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
# calculate the displacements needed to
|
|
|
|
|
# have lowest value for each axis at coordinate 0
|
2013-06-16 10:21:25 +00:00
|
|
|
|
my $bb = $self->bounding_box;
|
|
|
|
|
my @shift = map -$bb->extents->[$_][MIN], X,Y,Z;
|
2013-06-13 12:33:10 +00:00
|
|
|
|
$self->move(@shift);
|
|
|
|
|
return @shift;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub move {
|
|
|
|
|
my $self = shift;
|
2013-06-22 17:36:50 +00:00
|
|
|
|
my @shift = @_;
|
|
|
|
|
|
2013-09-11 07:49:28 +00:00
|
|
|
|
$_->mesh->translate(@shift) for @{$self->volumes};
|
2013-06-22 17:36:50 +00:00
|
|
|
|
$self->_bounding_box->translate(@shift) if defined $self->_bounding_box;
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-21 18:56:19 +00:00
|
|
|
|
sub scale {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($factor) = @_;
|
|
|
|
|
return if $factor == 1;
|
|
|
|
|
|
2013-09-11 07:49:28 +00:00
|
|
|
|
$_->mesh->scale($factor) for @{$self->volumes};
|
2013-06-22 17:36:50 +00:00
|
|
|
|
$self->_bounding_box->scale($factor) if defined $self->_bounding_box;
|
2012-10-21 18:56:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
sub rotate {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($deg) = @_;
|
|
|
|
|
return if $deg == 0;
|
|
|
|
|
|
2013-09-11 07:49:28 +00:00
|
|
|
|
$_->mesh->rotate($deg, Slic3r::Point->(0,0)) for @{$self->volumes};
|
2013-06-22 17:36:50 +00:00
|
|
|
|
$self->_bounding_box(undef);
|
2013-05-18 14:48:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 20:44:08 +00:00
|
|
|
|
sub materials_count {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
my %materials = map { $_->material_id // '_default' => 1 } @{$self->volumes};
|
|
|
|
|
return scalar keys %materials;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 17:52:32 +00:00
|
|
|
|
sub unique_materials {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
my %materials = ();
|
|
|
|
|
$materials{ $_->material_id // '_' } = 1 for @{$self->volumes};
|
|
|
|
|
return sort keys %materials;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 16:01:59 +00:00
|
|
|
|
sub facets_count {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
return sum(map $_->facets_count, @{$self->volumes});
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 13:10:11 +00:00
|
|
|
|
sub needed_repair {
|
|
|
|
|
my $self = shift;
|
2013-09-09 22:40:46 +00:00
|
|
|
|
return (first { !$_->mesh->needed_repair } @{$self->volumes}) ? 0 : 1;
|
2013-07-31 13:10:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 12:46:38 +00:00
|
|
|
|
sub mesh_stats {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
# TODO: sum values from all volumes
|
|
|
|
|
return $self->volumes->[0]->mesh->stats;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 13:10:11 +00:00
|
|
|
|
sub print_info {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
printf "Info about %s:\n", basename($self->input_file);
|
|
|
|
|
printf " size: x=%.3f y=%.3f z=%.3f\n", @{$self->size};
|
|
|
|
|
if (my $stats = $self->mesh_stats) {
|
|
|
|
|
printf " number of facets: %d\n", $stats->{number_of_facets};
|
|
|
|
|
printf " number of shells: %d\n", $stats->{number_of_parts};
|
|
|
|
|
printf " volume: %.3f\n", $stats->{volume};
|
|
|
|
|
if ($self->needed_repair) {
|
|
|
|
|
printf " needed repair: yes\n";
|
|
|
|
|
printf " degenerate facets: %d\n", $stats->{degenerate_facets};
|
|
|
|
|
printf " edges fixed: %d\n", $stats->{edges_fixed};
|
|
|
|
|
printf " facets removed: %d\n", $stats->{facets_removed};
|
|
|
|
|
printf " facets added: %d\n", $stats->{facets_added};
|
|
|
|
|
printf " facets reversed: %d\n", $stats->{facets_reversed};
|
|
|
|
|
printf " backwards edges: %d\n", $stats->{backwards_edges};
|
|
|
|
|
} else {
|
|
|
|
|
printf " needed repair: no\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
printf " number of facets: %d\n", scalar(map @{$_->facets}, @{$self->volumes});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 14:31:50 +00:00
|
|
|
|
sub clone { dclone($_[0]) }
|
|
|
|
|
|
2012-08-29 14:49:38 +00:00
|
|
|
|
package Slic3r::Model::Volume;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
|
|
has 'object' => (is => 'ro', weak_ref => 1, required => 1);
|
|
|
|
|
has 'material_id' => (is => 'rw');
|
2013-09-11 07:49:28 +00:00
|
|
|
|
has 'mesh' => (is => 'rw', required => 1);
|
2013-08-25 16:01:59 +00:00
|
|
|
|
|
2012-08-29 14:49:38 +00:00
|
|
|
|
package Slic3r::Model::Instance;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
|
|
has 'object' => (is => 'ro', weak_ref => 1, required => 1);
|
2013-05-31 17:41:31 +00:00
|
|
|
|
has 'rotation' => (is => 'rw', default => sub { 0 }); # around mesh center point
|
2013-06-13 12:33:10 +00:00
|
|
|
|
has 'scaling_factor' => (is => 'rw', default => sub { 1 });
|
2013-11-24 21:42:52 +00:00
|
|
|
|
has 'offset' => (is => 'rw'); # must be Slic3r::Point object in scaled coordinates
|
2012-08-29 14:49:38 +00:00
|
|
|
|
|
|
|
|
|
1;
|