More work for refactoring add_model() to add_model_object(). Tests pass

This commit is contained in:
Alessandro Ranellucci 2013-12-09 01:12:37 +01:00
parent 0339d5423d
commit f55e057504
6 changed files with 10 additions and 33 deletions

View File

@ -704,7 +704,8 @@ sub export_gcode2 {
eval {
$print->config->validate;
$print->add_model($self->make_model);
my $model = $self->make_model;
$print->add_model_object($_) for @{$model->objects};
$print->validate;
{
@ -1290,7 +1291,7 @@ has 'transformed_thumbnail' => (is => 'rw');
has 'thumbnail_scaling_factor' => (is => 'rw', trigger => \&_transform_thumbnail);
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new });
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => extruder_idx }
has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => region_id }
has 'mesh_stats' => (is => 'ro', required => 1);
# statistics

View File

@ -311,7 +311,7 @@ has 'volumes' => (is => 'ro', default => sub { [] });
has 'instances' => (is => 'rw'); # in unscaled coordinates
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new });
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => extruder_idx }
has 'material_mapping' => (is => 'rw', default => sub { {} }); # { material_id => region_idx }
has '_bounding_box' => (is => 'rw');
sub add_volume {

View File

@ -81,15 +81,6 @@ sub add_model_object {
my $self = shift;
my ($object) = @_;
# optimization: if avoid_crossing_perimeters is enabled, split
# this mesh into distinct objects so that we reduce the complexity
# of the graphs
# -- Disabling this one because there are too many legit objects having nested shells
# -- It also caused a bug where plater rotation was applied to each single object by the
# -- code below (thus around its own center), instead of being applied to the whole
# -- thing before the split.
###$model->split_meshes if $Slic3r::Config->avoid_crossing_perimeters && !$Slic3r::Config->complete_objects;
# read the material mapping provided by the model object, if any
my %matmap = %{ $object->material_mapping || {} };
$_-- for values %matmap; # extruders in the mapping are 1-indexed but we want 0-indexed
@ -115,10 +106,11 @@ sub add_model_object {
$meshes{$region_id}->merge($volume->mesh);
}
# bounding box of the original meshes in original position in unscaled coordinates
my $bb1 = Slic3r::Geometry::BoundingBox->merge(map $_->bounding_box, values %meshes);
foreach my $mesh (values %meshes) {
# align meshes to origin before applying transformations
# align meshes to object origin before applying transformations
$mesh->translate(@{$bb1->vector_to_origin});
# the order of these transformations must be the same as the one used in plater
@ -130,7 +122,7 @@ sub add_model_object {
$mesh->rotate($object->instances->[0]->rotation, $object->center_2D);
$mesh->scale($object->instances->[0]->scaling_factor);
}
$mesh->repair;
$mesh->repair; # needed? TODO: try without
}
# we align object also after transformations so that we only work with positive coordinates
@ -159,12 +151,7 @@ sub add_model_object {
push @{$self->objects}, Slic3r::Print::Object->new(
print => $self,
meshes => [ map $meshes{$_}, 0..$#{$self->regions} ],
copies => [
map Slic3r::Point->new(@$_),
$object->instances
? (map [ scale($_->offset->[X] - $align[X]) - $align2[X], scale($_->offset->[Y] - $align[Y]) - $align2[Y] ], @{$object->instances})
: [0,0],
],
copies => [ @copies ],
size => $scaled_bb->size, # transformed size
input_file => $object->input_file,
config_overrides => $object->config,

View File

@ -108,7 +108,7 @@ sub init_print {
$model_name = [$model_name] if ref($model_name) ne 'ARRAY';
for my $model (map model($_, %params), @$model_name) {
$model->arrange_objects($config);
$print->add_model($model);
$print->add_model_object($_) for @{$model->objects};
}
$print->validate;

View File

@ -20,6 +20,7 @@ extern "C" {
#define EPSILON 1e-4
#define SCALING_FACTOR 0.000001
#define scale_(val) (val / SCALING_FACTOR)
#define unscale(val) (val * SCALING_FACTOR)
namespace Slic3r {}

View File

@ -24,8 +24,6 @@
void rotate(double angle, Point* center);
TriangleMeshPtrs split();
void merge(TriangleMesh* mesh);
ExPolygons horizontal_projection()
%code{% THIS->horizontal_projection(RETVAL); %};
%{
SV*
@ -161,16 +159,6 @@ TriangleMesh::bb3()
OUTPUT:
RETVAL
Polygon*
TriangleMesh::convex_hull()
PREINIT:
const char* CLASS = "Slic3r::Polygon";
CODE:
RETVAL = new Polygon ();
THIS->convex_hull(*RETVAL);
OUTPUT:
RETVAL
%}
};