Added mirror factors to .3mf import and enabled import factors

This commit is contained in:
Enrico Turri 2018-10-22 13:27:53 +02:00
parent 84de664fb5
commit 2a2d1d85f8
3 changed files with 23 additions and 5 deletions

View file

@ -1249,14 +1249,25 @@ namespace Slic3r {
void _3MF_Importer::_apply_transform(ModelInstance& instance, const Transform3d& transform)
{
// slic3r ModelInstance cannot be transformed using a matrix
// we extract from the given matrix only the values currently used
// translation
Vec3d offset = transform.matrix().block(0, 3, 3, 1);
// scale
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
#if ENABLE_MIRROR
// mirror
// it is impossible to reconstruct the original mirroring factors from a matrix,
// we can only detect if the matrix contains a left handed reference system
// in which case we reorient it back to right handed by mirroring the x axis
Vec3d mirror = Vec3d::Ones();
if (m3x3.col(0).dot(m3x3.col(1).cross(m3x3.col(2))) < 0.0)
{
mirror(0) = -1.0;
// remove mirror
m3x3.col(0) *= -1.0;
}
// scale
#endif // ENABLE_MIRROR
Vec3d scale(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm());
// invalid scale value, return
@ -1273,6 +1284,9 @@ namespace Slic3r {
instance.set_offset(offset);
instance.set_scaling_factor(scale);
instance.set_rotation(rotation);
#if ENABLE_MIRROR
instance.set_mirror(mirror);
#endif // ENABLE_MIRROR
}
bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)

View file

@ -711,9 +711,13 @@ void ModelObject::center_around_origin()
if (!this->instances.empty()) {
for (ModelInstance *i : this->instances) {
#if ENABLE_MIRROR
i->set_offset(i->get_offset() - shift);
#else
// apply rotation and scaling to vector as well before translating instance,
// in order to leave final position unaltered
i->set_offset(i->get_offset() + i->transform_vector(-shift, true));
#endif // ENABLE_MIRROR
}
this->invalidate_bounding_box();
}

View file

@ -11,7 +11,7 @@
// New selections
#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_1_42_0)
// Add mirror components along the three axes in ModelInstance and GLVolume
#define ENABLE_MIRROR (0 && ENABLE_1_42_0)
#define ENABLE_MIRROR (1 && ENABLE_1_42_0)
#endif // _technologies_h_