adapt mesh function calls

This commit is contained in:
Michael Kirsch 2019-05-25 01:45:37 +02:00 committed by Joseph Lenox
parent 1da02f02c2
commit 68de2ba4b8
6 changed files with 29 additions and 33 deletions

View File

@ -366,7 +366,7 @@ sub on_btn_load {
$new_volume->set_input_file_vol_idx($vol_idx); $new_volume->set_input_file_vol_idx($vol_idx);
# apply the same translation we applied to the object # apply the same translation we applied to the object
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation}); $new_volume->translate(@{$self->{model_object}->origin_translation});
# set a default extruder value, since user can't add it manually # set a default extruder value, since user can't add it manually
$new_volume->config->set_ifndef('extruder', 0); $new_volume->config->set_ifndef('extruder', 0);
@ -405,11 +405,11 @@ sub on_btn_lambda {
$params->{"slab_h"}, $params->{"slab_h"},
); );
# box sets the base coordinate at 0,0, move to center of plate # box sets the base coordinate at 0,0, move to center of plate
$mesh->translate( #$mesh->translate(
-$size->x*1.5/2.0, # -$size->x*1.5/2.0,
-$size->y*1.5/2.0, #** # -$size->y*1.5/2.0, #**
0, # 0,
); #);
} else { } else {
return; return;
} }
@ -418,7 +418,7 @@ sub on_btn_lambda {
if (!$Slic3r::GUI::Settings->{_}{autocenter}) { if (!$Slic3r::GUI::Settings->{_}{autocenter}) {
#TODO what we really want to do here is just align the #TODO what we really want to do here is just align the
# center of the modifier to the center of the part. # center of the modifier to the center of the part.
$mesh->translate($center->x, $center->y, 0); #$mesh->translate($center->x, $center->y, 0);
} }
$mesh->repair; $mesh->repair;
@ -497,7 +497,7 @@ sub _update {
my $itemData = $self->get_selection; my $itemData = $self->get_selection;
if ($itemData && $itemData->{type} eq 'volume') { if ($itemData && $itemData->{type} eq 'volume') {
my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}]; my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
$volume->mesh->translate(@{ $volume->mesh->bounding_box->min_point->vector_to($self->{move_target}) }); $volume->translate(@{ $volume->mesh->bounding_box->min_point->vector_to($self->{move_target}) });
} }
$self->{parts_changed} = 1; $self->{parts_changed} = 1;

View File

@ -158,7 +158,7 @@ if (@ARGV) { # slicing from command line
my $model = Slic3r::Model->read_from_file($file); my $model = Slic3r::Model->read_from_file($file);
$model->add_default_instances; $model->add_default_instances;
my $mesh = $model->mesh; my $mesh = $model->mesh;
$mesh->translate(0, 0, -$mesh->bounding_box->z_min); $mesh->align_to_bed();
my $upper = Slic3r::TriangleMesh->new; my $upper = Slic3r::TriangleMesh->new;
my $lower = Slic3r::TriangleMesh->new; my $lower = Slic3r::TriangleMesh->new;
$mesh->cut(Z, $opt{cut}, $upper, $lower); $mesh->cut(Z, $opt{cut}, $upper, $lower);
@ -179,8 +179,8 @@ if (@ARGV) { # slicing from command line
my $model = Slic3r::Model->read_from_file($file); my $model = Slic3r::Model->read_from_file($file);
$model->add_default_instances; $model->add_default_instances;
my $mesh = $model->mesh; my $mesh = $model->mesh;
$mesh->align_to_bed();
my $bb = $mesh->bounding_box; my $bb = $mesh->bounding_box;
$mesh->translate(0, 0, -$bb->z_min);
my $x_parts = ceil(($bb->size->x - epsilon)/$grid_x); my $x_parts = ceil(($bb->size->x - epsilon)/$grid_x);
my $y_parts = ceil(($bb->size->y - epsilon)/$grid_y); #-- my $y_parts = ceil(($bb->size->y - epsilon)/$grid_y); #--

View File

@ -42,7 +42,7 @@ my %opt = (
$model->add_default_instances; $model->add_default_instances;
$model->center_instances_around_point(Slic3r::Pointf->new(100,100)); $model->center_instances_around_point(Slic3r::Pointf->new(100,100));
my $mesh = $model->mesh; my $mesh = $model->mesh;
$mesh->translate(0, 0, -$mesh->bounding_box->z_min); $mesh->align_to_bed();
# get slices # get slices
my @z = (); my @z = ();

View File

@ -1141,13 +1141,8 @@ ModelInstance::swap(ModelInstance &other)
void void
ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
{ {
mesh->rotate_z(this->rotation); // rotate around mesh origin TransformationMatrix trafo = this->get_trafo_matrix(dont_translate);
mesh->transform(trafo);
mesh->scale(this->scaling_factor); // scale around mesh origin
if (!dont_translate) {
mesh->translate(this->offset.x, this->offset.y, 0);
}
} }
TransformationMatrix ModelInstance::get_trafo_matrix(bool dont_translate) const TransformationMatrix ModelInstance::get_trafo_matrix(bool dont_translate) const

View File

@ -3,6 +3,7 @@
#include "ClipperUtils.hpp" #include "ClipperUtils.hpp"
#include "Geometry.hpp" #include "Geometry.hpp"
#include "Log.hpp" #include "Log.hpp"
#include "TransformationMatrix.hpp"
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <limits> #include <limits>
@ -936,28 +937,28 @@ PrintObject::_slice_region(size_t region_id, std::vector<float> z, bool modifier
// compose mesh // compose mesh
TriangleMesh mesh; TriangleMesh mesh;
// we ignore the per-instance transformations currently and only
// consider the first one
TransformationMatrix trafo = object.instances[0]->get_trafo_matrix();
// align mesh to Z = 0 (it should be already aligned actually) and apply XY shift
trafo.translate(
-unscale(this->_copies_shift.x),
-unscale(this->_copies_shift.y),
-object.bounding_box().min.z
);
for (const auto& i : region_volumes) { for (const auto& i : region_volumes) {
const ModelVolume &volume = *(object.volumes[i]); const ModelVolume &volume = *(object.volumes[i]);
if (volume.modifier != modifier) continue; if (volume.modifier != modifier) continue;
mesh.merge(volume.mesh); mesh.merge(volume.get_transformed_mesh(&trafo));
} }
if (mesh.facets_count() == 0) return layers; if (mesh.facets_count() == 0) return layers;
// transform mesh
// we ignore the per-instance transformations currently and only
// consider the first one
object.instances[0]->transform_mesh(&mesh, true);
// align mesh to Z = 0 (it should be already aligned actually) and apply XY shift
mesh.translate(
-unscale(this->_copies_shift.x),
-unscale(this->_copies_shift.y),
-object.bounding_box().min.z
);
// perform actual slicing // perform actual slicing
TriangleMeshSlicer<Z>(&mesh).slice(z, &layers); TriangleMeshSlicer<Z>(&mesh).slice(z, &layers);
return layers; return layers;

View File

@ -16,6 +16,8 @@ SLAPrint::slice()
TriangleMesh mesh = this->model->mesh(); TriangleMesh mesh = this->model->mesh();
mesh.repair(); mesh.repair();
mesh.align_to_bed();
// align to origin taking raft into account // align to origin taking raft into account
this->bb = mesh.bounding_box(); this->bb = mesh.bounding_box();
if (this->config.raft_layers > 0) { if (this->config.raft_layers > 0) {
@ -24,8 +26,6 @@ SLAPrint::slice()
this->bb.max.x += this->config.raft_offset.value; this->bb.max.x += this->config.raft_offset.value;
this->bb.max.y += this->config.raft_offset.value; this->bb.max.y += this->config.raft_offset.value;
} }
mesh.translate(0, 0, -bb.min.z);
this->bb.translate(0, 0, -bb.min.z);
// if we are generating a raft, first_layer_height will not affect mesh slicing // if we are generating a raft, first_layer_height will not affect mesh slicing
const float lh = this->config.layer_height.value; const float lh = this->config.layer_height.value;