Tech ENABLE_WORLD_COORDINATE_SCALE_REVISITED - Detection of required transformation baking done on mouse dragging event in place of mouse up event for gizmo scale

This commit is contained in:
enricoturri1966 2022-02-18 14:40:43 +01:00
parent 98a9dd2cec
commit 4ad05d17d3
4 changed files with 44 additions and 48 deletions

View file

@ -1272,17 +1272,16 @@ void ObjectManipulation::set_uniform_scaling(const bool use_uniform_scale)
const Selection &selection = wxGetApp().plater()->canvas3D()->get_selection(); const Selection &selection = wxGetApp().plater()->canvas3D()->get_selection();
#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED #if ENABLE_WORLD_COORDINATE_SCALE_REVISITED
if (!use_uniform_scale) { if (!use_uniform_scale) {
int res = selection.bake_transform_if_needed(false); int res = selection.bake_transform_if_needed();
if (res == -1) { if (res == -1) {
// Enforce uniform scaling. // Enforce uniform scaling.
m_lock_bnt->SetLock(true); m_lock_bnt->SetLock(true);
return; return;
} }
else if (res == 0) { else if (res == 0)
// Recalculate cached values at this panel, refresh the screen. // Recalculate cached values at this panel, refresh the screen.
this->UpdateAndShow(true); this->UpdateAndShow(true);
} }
}
m_uniform_scale = use_uniform_scale; m_uniform_scale = use_uniform_scale;
#else #else

View file

@ -576,30 +576,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
else if (is_dragging()) { else if (is_dragging()) {
switch (m_current) { switch (m_current) {
case Move: { m_parent.do_move(L("Gizmo-Move")); break; } case Move: { m_parent.do_move(L("Gizmo-Move")); break; }
#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED
case Scale: {
const Vec3d scale = get_scale();
const Vec3d starting_scale = get_starting_scale();
wxGetApp().CallAfter([this, &selection, scale, starting_scale]() {
int res = 1;
if (scale.x() != scale.y() || scale.x() != scale.z())
res = selection.bake_transform_if_needed(L("Gizmo-Scale"));
if (res == 1)
m_parent.do_scale(L("Gizmo-Scale"));
else if (res == -1) {
TransformationType transformation_type;
if (!wxGetApp().obj_manipul()->is_world_coordinates())
transformation_type.set_local();
selection.scale(starting_scale, transformation_type);
}
}
);
break;
}
#else
case Scale: { m_parent.do_scale(L("Gizmo-Scale")); break; } case Scale: { m_parent.do_scale(L("Gizmo-Scale")); break; }
#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED
case Rotate: { m_parent.do_rotate(L("Gizmo-Rotate")); break; } case Rotate: { m_parent.do_rotate(L("Gizmo-Rotate")); break; }
default: break; default: break;
} }
@ -668,6 +645,30 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
} }
case Scale: case Scale:
{ {
#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED
const Vec3d scale = get_scale();
int res = 1;
if (scale.x() != scale.y() || scale.x() != scale.z()) {
// we need to release the mouse or, if the modal dialog is shown by the
// following call to bake_transform_if_needed(), the focus gets messed up
if (m_parent.get_wxglcanvas()->HasCapture())
m_parent.get_wxglcanvas()->ReleaseMouse();
res = selection.bake_transform_if_needed();
// re-capture the mouse
if (!m_parent.get_wxglcanvas()->HasCapture())
m_parent.get_wxglcanvas()->CaptureMouse();
}
if (res != 1) {
// the modal dialog has been disposed, fake mouse up
stop_dragging();
update_data();
m_parent.mouse_up_cleanup();
}
else {
#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED
// Apply new temporary scale factors // Apply new temporary scale factors
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
TransformationType transformation_type; TransformationType transformation_type;
@ -686,6 +687,9 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
selection.translate(get_scale_offset(), true); selection.translate(get_scale_offset(), true);
#endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_WORLD_COORDINATE
wxGetApp().obj_manipul()->set_dirty(); wxGetApp().obj_manipul()->set_dirty();
#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED
}
#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED
break; break;
} }
case Rotate: case Rotate:

View file

@ -1309,7 +1309,7 @@ void Selection::translate(unsigned int object_idx, unsigned int instance_idx, co
} }
#if ENABLE_WORLD_COORDINATE_SCALE_REVISITED #if ENABLE_WORLD_COORDINATE_SCALE_REVISITED
int Selection::bake_transform_if_needed(bool apply_scale) const int Selection::bake_transform_if_needed() const
{ {
if ((is_single_full_instance() && wxGetApp().obj_manipul()->is_world_coordinates()) || if ((is_single_full_instance() && wxGetApp().obj_manipul()->is_world_coordinates()) ||
(is_single_volume_or_modifier() && !wxGetApp().obj_manipul()->is_local_coordinates())) { (is_single_volume_or_modifier() && !wxGetApp().obj_manipul()->is_local_coordinates())) {
@ -1347,12 +1347,6 @@ int Selection::bake_transform_if_needed(bool apply_scale) const
if (dlg.ShowModal() != wxID_YES) if (dlg.ShowModal() != wxID_YES)
return -1; return -1;
if (apply_scale) {
wxGetApp().plater()->get_current_canvas3D()->do_scale(L("Scale + Bake transform"));
Plater::SuppressSnapshots suppress(wxGetApp().plater());
wxGetApp().plater()->take_snapshot(_("Bake transform"));
}
else
wxGetApp().plater()->take_snapshot(_("Bake transform")); wxGetApp().plater()->take_snapshot(_("Bake transform"));
// Bake the rotation into the meshes of the object. // Bake the rotation into the meshes of the object.

View file

@ -374,8 +374,7 @@ public:
// -1 if the user refused to proceed with baking when asked // -1 if the user refused to proceed with baking when asked
// 0 if the baking was performed // 0 if the baking was performed
// 1 if no baking was needed // 1 if no baking was needed
// if apply_scale == true the scaling of the current selection is applied int bake_transform_if_needed() const;
int bake_transform_if_needed(bool apply_scale) const;
#endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED #endif // ENABLE_WORLD_COORDINATE_SCALE_REVISITED
void erase(); void erase();