Fixed flatten gizmo's flattening normal

This commit is contained in:
Enrico Turri 2018-09-05 14:02:08 +02:00
parent 407aee9942
commit 011281068b
3 changed files with 5 additions and 8 deletions

View file

@ -1738,10 +1738,7 @@ namespace Slic3r {
stream << " </" << COMPONENTS_TAG << ">\n"; stream << " </" << COMPONENTS_TAG << ">\n";
} }
Transform3d t = Transform3d::Identity(); Transform3d t = instance->world_matrix();
t.translate(Vec3d(instance->offset(0), instance->offset(1), 0.0));
t.rotate(Eigen::AngleAxisd(instance->rotation, Vec3d::UnitZ()));
t.scale(instance->scaling_factor);
build_items.emplace_back(instance_id, t); build_items.emplace_back(instance_id, t);
stream << " </" << OBJECT_TAG << ">\n"; stream << " </" << OBJECT_TAG << ">\n";

View file

@ -2999,9 +2999,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (m_gizmos.get_current_type() == Gizmos::Flatten) { if (m_gizmos.get_current_type() == Gizmos::Flatten) {
// Rotate the object so the normal points downward: // Rotate the object so the normal points downward:
Vec3d normal = m_gizmos.get_flattening_normal(); Vec3d normal = m_gizmos.get_flattening_normal();
if (normal != Vec3d::Zero()) { if (normal(0) != 0.0 || normal(1) != 0.0 || normal(2) != 0.0) {
Vec3d axis = normal(2) > 0.999f ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()); Vec3d axis = normal(2) > 0.999 ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()).normalized();
float angle = acos(-normal(2)); float angle = acos(clamp(-1.0, 1.0, -normal(2)));
m_on_gizmo_rotate_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2)); m_on_gizmo_rotate_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2));
} }
} }

View file

@ -1282,7 +1282,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
Vec3d GLGizmoFlatten::get_flattening_normal() const { Vec3d GLGizmoFlatten::get_flattening_normal() const {
Vec3d normal = m_model_object->instances.front()->world_matrix().matrix().block(0, 0, 3, 3) * m_normal; Vec3d normal = m_model_object->instances.front()->world_matrix().matrix().block(0, 0, 3, 3) * m_normal;
m_normal = Vec3d::Zero(); m_normal = Vec3d::Zero();
return normal; return normal.normalized();
} }
} // namespace GUI } // namespace GUI