diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index b8a309bc6058..22a9ac98166e 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -421,6 +421,10 @@ void Polygon2DEditor::_cancel_editing() { } else if (uv_edit_mode[1]->is_pressed()) { // Edit polygon. node->set_polygon(points_prev); } + if (uv_move_current == UV_MODE_MOVE_PIVOT) { + uv_move_current = UV_MODE_EDIT_POINT; + node->set_offset(offset_prev); + } } polygon_create.clear(); @@ -623,6 +627,8 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { undo_redo->commit_action(); } + const real_t grab_radius = EDITOR_GET("editors/polygon_editor/point_grab_radius"); + if (uv_move_current == UV_MODE_REMOVE_INTERNAL) { uv_create_uv_prev = node->get_uv(); uv_create_poly_prev = node->get_polygon(); @@ -640,7 +646,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) { Vector2 tuv = mtx.xform(uv_create_poly_prev[i]); real_t dist = tuv.distance_to(mb->get_position()); - if (dist < 8 && dist < closest_dist) { + if (dist < grab_radius && dist < closest_dist) { closest = i; closest_dist = dist; } @@ -692,14 +698,21 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { point_drag_index = -1; for (int i = 0; i < points_prev.size(); i++) { Vector2 tuv = mtx.xform(points_prev[i]); - if (tuv.distance_to(mb->get_position()) < 8) { + if (tuv.distance_to(mb->get_position()) < grab_radius) { uv_drag_from = tuv; point_drag_index = i; } } if (point_drag_index == -1) { - uv_drag = false; + Vector2 offset_transformed = mtx.xform(-node->get_offset()); + if (uv_edit_mode[1]->is_pressed() && offset_transformed.distance_to(mb->get_position()) < grab_radius) { + uv_drag_from = offset_transformed; + offset_prev = node->get_offset(); + uv_move_current = UV_MODE_MOVE_PIVOT; + } else { + uv_drag = false; + } } } @@ -710,7 +723,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { for (int i = 0; i < points_prev.size(); i++) { Vector2 tuv = mtx.xform(points_prev[i]); real_t dist = tuv.distance_to(mb->get_position()); - if (dist < 8 && dist < closest_dist) { + if (dist < grab_radius && dist < closest_dist) { closest = i; closest_dist = dist; } @@ -816,6 +829,15 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { undo_redo->add_undo_method(uv_edit_draw, "queue_redraw"); undo_redo->commit_action(); } break; + case UV_MODE_MOVE_PIVOT: { + undo_redo->create_action(TTR("Set Offset")); + undo_redo->add_do_method(node, "set_offset", node->get_offset()); + undo_redo->add_undo_method(node, "set_offset", offset_prev); + undo_redo->add_do_method(uv_edit_draw, "queue_redraw"); + undo_redo->add_undo_method(uv_edit_draw, "queue_redraw"); + undo_redo->commit_action(); + uv_move_current = UV_MODE_EDIT_POINT; + } break; default: { } break; } @@ -869,6 +891,9 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { node->set_polygon(uv_new); } } break; + case UV_MODE_MOVE_PIVOT: { + node->set_offset(offset_prev - drag); + } break; case UV_MODE_MOVE: { Vector uv_new = points_prev; for (int i = 0; i < uv_new.size(); i++) { @@ -1239,6 +1264,11 @@ void Polygon2DEditor::_uv_draw() { } } + if (uv_edit_mode[1]->is_pressed()) { + Ref pivot_icon = get_editor_theme_icon(SNAME("EditorPivot")); + uv_edit_draw->draw_texture(pivot_icon, mtx.xform(-node->get_offset()) - pivot_icon->get_size() * 0.5); + } + if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) { NodePath bone_path; for (int i = 0; i < bone_scroll_vb->get_child_count(); i++) { diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index 164aa3eccc83..bf413e414e7e 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -70,6 +70,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { UV_MODE_REMOVE_POLYGON, UV_MODE_PAINT_WEIGHT, UV_MODE_CLEAR_WEIGHT, + UV_MODE_MOVE_PIVOT, UV_MODE_MAX }; @@ -120,6 +121,7 @@ class Polygon2DEditor : public AbstractPolygon2DEditor { int uv_create_prev_internal_vertices = 0; Array uv_create_bones_prev; Array polygons_prev; + Vector2 offset_prev; Vector2 uv_create_to; int point_drag_index;