Make quick_slice() work with new model handling
This commit is contained in:
parent
0e8a0ef1ca
commit
5470fbbebc
6 changed files with 32 additions and 25 deletions
|
@ -159,4 +159,8 @@ sub open {
|
|||
return CORE::open $$fh, $mode, encode_path($filename);
|
||||
}
|
||||
|
||||
# this package declaration prevents an ugly fatal warning to be emitted when
|
||||
# spawning a new thread
|
||||
package GLUquadricObjPtr;
|
||||
|
||||
1;
|
||||
|
|
|
@ -638,7 +638,7 @@ sub export_gcode {
|
|||
# select output file
|
||||
$self->{output_file} = $main::opt{output};
|
||||
{
|
||||
$self->{output_file} = $self->skeinpanel->init_print->expanded_output_filepath($self->{output_file}, $self->{objects}[0]->input_file);
|
||||
$self->{output_file} = $self->skeinpanel->init_print->expanded_output_filepath($self->{output_file}, $self->{model}->objects->[0]->input_file);
|
||||
my $dlg = Wx::FileDialog->new($self, 'Save G-code file as:', Slic3r::GUI->output_path(dirname($self->{output_file})),
|
||||
basename($self->{output_file}), &Slic3r::GUI::SkeinPanel::FILE_WILDCARDS->{gcode}, wxFD_SAVE);
|
||||
if ($dlg->ShowModal != wxID_OK) {
|
||||
|
@ -653,8 +653,6 @@ sub export_gcode {
|
|||
|
||||
$self->statusbar->StartBusy;
|
||||
|
||||
$_->free_model_object for @{$self->{objects}};
|
||||
|
||||
# It looks like declaring a local $SIG{__WARN__} prevents the ugly
|
||||
# "Attempt to free unreferenced scalar" warning...
|
||||
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
|
||||
|
@ -727,6 +725,7 @@ sub export_gcode2 {
|
|||
{
|
||||
my @warnings = ();
|
||||
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
||||
|
||||
my %params = (
|
||||
output_file => $output_file,
|
||||
status_cb => sub { $params{progressbar}->(@_) },
|
||||
|
@ -966,6 +965,7 @@ sub repaint {
|
|||
next unless defined $object->thumbnail;
|
||||
for my $instance_idx (0 .. $#{$model_object->instances}) {
|
||||
my $instance = $model_object->instances->[$instance_idx];
|
||||
next if !defined $object->transformed_thumbnail;
|
||||
|
||||
my $thumbnail = $object->transformed_thumbnail->clone; # in scaled coordinates
|
||||
$thumbnail->scale(&Slic3r::SCALING_FACTOR * $parent->{scaling_factor}); # in unscaled pixels
|
||||
|
|
|
@ -134,7 +134,17 @@ sub quick_slice {
|
|||
Slic3r::GUI->save_settings;
|
||||
|
||||
my $print = $self->init_print;
|
||||
$print->add_model(Slic3r::Model->read_from_file($input_file));
|
||||
my $model = Slic3r::Model->read_from_file($input_file);
|
||||
|
||||
if ($model->has_objects_with_no_instances) {
|
||||
# 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;
|
||||
}
|
||||
$model->arrange_objects($config);
|
||||
}
|
||||
|
||||
$print->add_model_object($_) for @{ $model->objects };
|
||||
$print->validate;
|
||||
|
||||
# select output file
|
||||
|
|
|
@ -110,15 +110,9 @@ sub add_model_object {
|
|||
my $bb1 = Slic3r::Geometry::BoundingBox->merge(map $_->bounding_box, values %meshes);
|
||||
|
||||
foreach my $mesh (values %meshes) {
|
||||
# the order of these transformations must be the same as the one used in plater
|
||||
# to make the object positioning consistent with the visual preview
|
||||
|
||||
# we ignore the per-instance transformations currently and only
|
||||
# consider the first one
|
||||
if ($object->instances && @{$object->instances}) {
|
||||
$mesh->rotate($object->instances->[0]->rotation, Slic3r::Point->new(0,0));
|
||||
$mesh->scale($object->instances->[0]->scaling_factor);
|
||||
}
|
||||
$object->instances->[0]->transform_mesh($mesh);
|
||||
}
|
||||
|
||||
# we align object also after transformations so that we only work with positive coordinates
|
||||
|
@ -133,23 +127,20 @@ sub add_model_object {
|
|||
|
||||
# prepare copies
|
||||
my @copies = ();
|
||||
if ($object->instances) {
|
||||
foreach my $instance (@{ $object->instances }) {
|
||||
push @copies, Slic3r::Point->new(
|
||||
scale($instance->offset->[X] - $bb1->extents->[X][MIN])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
push @copies, Slic3r::Point->new(0,0);
|
||||
foreach my $instance (@{ $object->instances }) {
|
||||
push @copies, Slic3r::Point->new(
|
||||
scale($instance->offset->[X] - $bb1->extents->[X][MIN]),
|
||||
scale($instance->offset->[Y] - $bb1->extents->[Y][MIN]),
|
||||
);
|
||||
}
|
||||
|
||||
# initialize print object
|
||||
push @{$self->objects}, Slic3r::Print::Object->new(
|
||||
print => $self,
|
||||
meshes => [ map $meshes{$_}, 0..$#{$self->regions} ],
|
||||
copies => [ @copies ],
|
||||
size => $scaled_bb->size, # transformed size
|
||||
input_file => $object->input_file,
|
||||
print => $self,
|
||||
meshes => [ map $meshes{$_}, 0..$#{$self->regions} ],
|
||||
copies => [ @copies ],
|
||||
size => $scaled_bb->size, # transformed size
|
||||
input_file => $object->input_file,
|
||||
config_overrides => $object->config,
|
||||
layer_height_ranges => $object->layer_height_ranges,
|
||||
);
|
||||
|
|
|
@ -118,7 +118,7 @@ sub slice {
|
|||
# process facets
|
||||
for my $region_id (0 .. $#{$self->meshes}) {
|
||||
my $mesh = $self->meshes->[$region_id] // next; # ignore undef meshes
|
||||
|
||||
|
||||
{
|
||||
my $loops = $mesh->slice([ map $_->slice_z, @{$self->layers} ]);
|
||||
for my $layer_id (0..$#$loops) {
|
||||
|
|
|
@ -191,6 +191,8 @@ TriangleMesh::slice(const std::vector<double> &z, std::vector<Polygons> &layers)
|
|||
FUTURE: parallelize slice_facet() and make_loops()
|
||||
*/
|
||||
|
||||
if (!this->repaired) this->repair();
|
||||
|
||||
// build a table to map a facet_idx to its three edge indices
|
||||
if (this->stl.v_shared == NULL) stl_generate_shared_vertices(&(this->stl));
|
||||
typedef std::pair<int,int> t_edge;
|
||||
|
|
Loading…
Reference in a new issue