From 4c321cf554661d2532412db23983d00b8d1fbc3b Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Fri, 17 Feb 2023 16:49:55 +0100 Subject: [PATCH] Keep up rotation --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index ce1c98a35..45e2623e0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -680,8 +680,19 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event) Transform3d world_new = z_rotation * m_surface_drag->world; auto world_new_linear = world_new.linear(); - // Fix up vector ?? - //auto y_rotation = Eigen::Quaternion::FromTwoVectors(text_y_world, hit->normal); + if (true) + { + // Fix direction of up vector + Vec3d z_world = world_new_linear.col(2); + z_world.normalize(); + Vec3d wanted_up = suggest_up(z_world); + + Vec3d y_world = world_new_linear.col(1); + auto y_rotation = Eigen::Quaternion::FromTwoVectors(y_world, wanted_up); + + world_new = y_rotation * world_new; + world_new_linear = world_new.linear(); + } // Edit position from right Transform3d volume_new{Eigen::Translation(m_surface_drag->instance_inv * hit->position)}; @@ -701,12 +712,8 @@ bool GLGizmoEmboss::on_mouse_for_translate(const wxMouseEvent &mouse_event) if (tc.fix_3mf_tr.has_value()) volume_new = volume_new * (*tc.fix_3mf_tr); - // apply move in Z direction for move with flat surface above texture - const FontProp &prop = tc.style.prop; - if (!prop.use_surface && prop.distance.has_value()) { - Vec3d translate = Vec3d::UnitZ() * (*prop.distance); - volume_new.translate(translate); - } + // apply move in Z direction and rotation by up vector + apply_transformation(tc.style.prop, volume_new); // Update transformation for all instances for (GLVolume *vol : m_parent.get_volumes().volumes) {