From f55e057504a3c0bdacd641a0c34d486af1c97c1a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 9 Dec 2013 01:12:37 +0100 Subject: [PATCH] More work for refactoring add_model() to add_model_object(). Tests pass --- lib/Slic3r/GUI/Plater.pm | 5 +++-- lib/Slic3r/Model.pm | 2 +- lib/Slic3r/Print.pm | 21 ++++----------------- lib/Slic3r/Test.pm | 2 +- xs/src/myinit.h | 1 + xs/xsp/TriangleMesh.xsp | 12 ------------ 6 files changed, 10 insertions(+), 33 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index ee90576d9..14d5b026c 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -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 diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 6993fd35a..b1a11665d 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -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 { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 659fc3528..b555104b4 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -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, diff --git a/lib/Slic3r/Test.pm b/lib/Slic3r/Test.pm index 6f2b5d403..c857f3496 100644 --- a/lib/Slic3r/Test.pm +++ b/lib/Slic3r/Test.pm @@ -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; diff --git a/xs/src/myinit.h b/xs/src/myinit.h index d1659823e..1ef522b44 100644 --- a/xs/src/myinit.h +++ b/xs/src/myinit.h @@ -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 {} diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index db98a633e..8d6c42375 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -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 - %} };