New --cut feature

This commit is contained in:
Alessandro Ranellucci 2014-04-25 10:20:30 +02:00
parent 37c7b958d4
commit fe1691c151
7 changed files with 117 additions and 21 deletions

View file

@ -25,13 +25,15 @@ sub read_file {
sub write_file {
my $self = shift;
my ($file, $model, %params) = @_;
my ($file, $mesh, %params) = @_;
$mesh = $mesh->mesh if $mesh->isa('Slic3r::Model');
my $path = Slic3r::encode_path($file);
$params{binary}
? $model->mesh->write_binary($path)
: $model->mesh->write_ascii($path);
? $mesh->write_binary($path)
: $mesh->write_ascii($path);
}
1;

View file

@ -191,6 +191,21 @@ sub has_objects_with_no_instances {
return (first { !defined $_->instances } @{$self->objects}) ? 1 : 0;
}
# makes sure all objects have at least one instance
sub add_default_instances {
my ($self) = @_;
# apply a default position to all objects not having one
my $added = 0;
foreach my $object (@{$self->objects}) {
if (!defined $object->instances) {
$object->add_instance(offset => [0,0]);
$added = 1;
}
}
return $added;
}
# this returns the bounding box of the *transformed* instances
sub bounding_box {
my $self = shift;

View file

@ -46,13 +46,8 @@ sub set_model {
# make method idempotent so that the object is reusable
$self->_print->delete_all_objects;
my $need_arrange = $model->has_objects_with_no_instances;
if ($need_arrange) {
# apply a default position to all objects not having one
foreach my $object (@{$model->objects}) {
$object->add_instance(offset => [0,0]) if !defined $object->instances;
}
}
# make sure all objects have at least one defined instance
my $need_arrange = $model->add_default_instances;
# apply scaling and rotation supplied from command line if any
foreach my $instance (map @{$_->instances}, @{$model->objects}) {