Fix regression causing the plater to merge all materials into a single one, thus not producing multi-extrusion prints

This commit is contained in:
Alessandro Ranellucci 2012-10-21 20:56:19 +02:00
parent f5f9574173
commit 4f1b56f004
2 changed files with 43 additions and 15 deletions

View File

@ -455,7 +455,14 @@ sub split_object {
my ($obj_idx, $current_object) = $self->selected_object; my ($obj_idx, $current_object) = $self->selected_object;
my $current_copies_num = $current_object->instances_count; my $current_copies_num = $current_object->instances_count;
my $mesh = $current_object->get_mesh; my $model_object = $current_object->get_model_object;
if (@{$model_object->volumes} > 1) {
Slic3r::GUI::warning_catcher($self)->("The selected object couldn't be splitted because it contains more than one volume/material.");
return;
}
my $mesh = $model_object->mesh;
$mesh->align_to_origin; $mesh->align_to_origin;
my @new_meshes = $mesh->split_mesh; my @new_meshes = $mesh->split_mesh;
@ -669,20 +676,24 @@ sub make_model {
my $self = shift; my $self = shift;
my $model = Slic3r::Model->new; my $model = Slic3r::Model->new;
foreach my $object (@{$self->{objects}}) { foreach my $plater_object (@{$self->{objects}}) {
my $mesh = $object->get_mesh; my $model_object = $plater_object->get_model_object;
$mesh->scale($object->scale); my $new_model_object = $model->add_object(
my $model_object = $model->add_object( vertices => $model_object->vertices,
vertices => $mesh->vertices, input_file => $plater_object->input_file,
input_file => $object->input_file,
); );
$model_object->add_volume( foreach my $volume (@{$model_object->volumes}) {
facets => $mesh->facets, $new_model_object->add_volume(
); material_id => $volume->material_id,
$model_object->add_instance( facets => $volume->facets,
rotation => $object->rotate, );
$model->materials->{$volume->material_id || 0} ||= {};
}
$new_model_object->scale($plater_object->scale);
$new_model_object->add_instance(
rotation => $plater_object->rotate,
offset => [ @$_ ], offset => [ @$_ ],
) for @{$object->instances}; ) for @{$plater_object->instances};
} }
return $model; return $model;
@ -1027,12 +1038,12 @@ sub free_mesh {
$self->mesh(undef); $self->mesh(undef);
} }
sub get_mesh { sub get_model_object {
my $self = shift; my $self = shift;
return $self->mesh->clone if $self->mesh; return $self->mesh->clone if $self->mesh;
my $model = Slic3r::Model->read_from_file($self->input_file); my $model = Slic3r::Model->read_from_file($self->input_file);
return $model->objects->[$self->input_file_object_id]->mesh; return $model->objects->[$self->input_file_object_id];
} }
sub instances_count { sub instances_count {

View File

@ -37,6 +37,12 @@ sub set_material {
); );
} }
sub scale {
my $self = shift;
$_->scale(@_) for @{$self->objects};
}
# flattens everything to a single mesh # flattens everything to a single mesh
sub mesh { sub mesh {
my $self = shift; my $self = shift;
@ -112,6 +118,17 @@ sub mesh {
); );
} }
sub scale {
my $self = shift;
my ($factor) = @_;
return if $factor == 1;
# transform vertex coordinates
foreach my $vertex (@{$self->vertices}) {
$vertex->[$_] *= $factor for X,Y,Z;
}
}
package Slic3r::Model::Volume; package Slic3r::Model::Volume;
use Moo; use Moo;