Skip to content

Commit

Permalink
Another attempt to fix auto-orient
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Feb 19, 2024
1 parent fad15c0 commit 51fe1e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libslic3r/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ Vec3d extract_euler_angles(const Transform3d& transform)

void rotation_from_two_vectors(Vec3d from, Vec3d to, Vec3d& rotation_axis, double& phi, Matrix3d* rotation_matrix)
{
const Matrix3d m = Eigen::Quaterniond().setFromTwoVectors(from, to).toRotationMatrix();
const Matrix3d m = Eigen::Quaterniond().setFromTwoVectors(from, to).normalized().toRotationMatrix();
const Eigen::AngleAxisd aa(m);
rotation_axis = aa.axis();
phi = aa.angle();
Expand Down
7 changes: 3 additions & 4 deletions src/libslic3r/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,9 @@ class ModelInstance final : public ObjectBase

// BBS
void rotate(Matrix3d rotation_matrix) {
auto R = m_transformation.get_rotation_matrix().matrix().block<3, 3>(0, 0);
auto R_new = rotation_matrix * R;
auto euler_angles = Geometry::extract_euler_angles(R_new);
set_rotation(euler_angles);
auto rotation = m_transformation.get_rotation_matrix();
rotation = rotation_matrix * rotation;
set_rotation(Geometry::Transformation(rotation).get_rotation());
}

Vec3d get_scaling_factor() const { return m_transformation.get_scaling_factor(); }
Expand Down

0 comments on commit 51fe1e4

Please sign in to comment.