Rework mdr ed's gizmo so it's able to handle rect style selection later.

This commit is contained in:
Relintai 2022-01-25 13:32:03 +01:00
parent 6f8525a44b
commit 44f3ab6c5e

View File

@ -40,11 +40,14 @@ var visual_indicator_outline : bool = true
var visual_indicator_seam : bool= true var visual_indicator_seam : bool= true
var visual_indicator_handle : bool = true var visual_indicator_handle : bool = true
var previous_point : Vector2 var previous_point : Vector2
var is_dragging : bool = false var is_dragging : bool = false
var _last_known_camera_facing : Vector3 = Vector3(0, 0, -1) var _last_known_camera_facing : Vector3 = Vector3(0, 0, -1)
var _rect_drag : bool = false
var _rect_drag_start_point : Vector2 = Vector2()
var _rect_drag_min_ofset : float = 10
var _mdr : MeshDataResource = null var _mdr : MeshDataResource = null
var _vertices : PoolVector3Array var _vertices : PoolVector3Array
@ -208,61 +211,8 @@ func forward_spatial_gui_input(index, camera, event):
var grab_threshold : float = 8 var grab_threshold : float = 8
if event.get_button_index() == BUTTON_LEFT: if event.get_button_index() == BUTTON_LEFT:
if event.is_pressed(): if !event.is_pressed():
var mouse_pos = event.get_position() # If a handle was being dragged only run these
# if (_gizmo_select(p_index, _edit.mouse_pos))
# return true;
# select vertex
var closest_idx : int = -1
var closest_dist : float = 1e10
for i in range(_handle_points.size()):
var vert_pos_3d : Vector3 = gt.xform(_handle_points[i])
var vert_pos_2d : Vector2 = camera.unproject_position(vert_pos_3d)
var dist_3d : float = ray_from.distance_to(vert_pos_3d)
var dist_2d : float = gpoint.distance_to(vert_pos_2d)
if (dist_2d < grab_threshold && dist_3d < closest_dist):
closest_dist = dist_3d
closest_idx = i
if (closest_idx >= 0):
for si in range(_selected_points.size()):
if _selected_points[si] == closest_idx:
if event.control:
_selected_points.remove(si)
return true
return false
if event.control:
return false
if event.shift:
_selected_points.append(closest_idx)
else:
# Select new point only
_selected_points.resize(0)
_selected_points.append(closest_idx)
apply()
redraw()
else:
# Don't unselect all if either control or shift is held down
if event.shift || event.control:
return false
if _selected_points.size() == 0:
return false
#Unselect all
_selected_points.resize(0)
redraw()
else:
is_dragging = false is_dragging = false
if _handle_drag_op && _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null && _mdr.array[ArrayMesh.ARRAY_VERTEX].size() == _drag_op_orig_verices.size(): if _handle_drag_op && _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null && _mdr.array[ArrayMesh.ARRAY_VERTEX].size() == _drag_op_orig_verices.size():
@ -271,7 +221,77 @@ func forward_spatial_gui_input(index, camera, event):
_undo_redo.add_undo_method(self, "apply_vertex_array", _mdr, _drag_op_orig_verices) _undo_redo.add_undo_method(self, "apply_vertex_array", _mdr, _drag_op_orig_verices)
_undo_redo.commit_action() _undo_redo.commit_action()
_handle_drag_op = false if _handle_drag_op:
_handle_drag_op = false
return true
# See whether we should check for a click or a selection box
var mouse_pos : Vector2 = event.get_position()
var rect_size : Vector2 = _rect_drag_start_point - mouse_pos
rect_size.x = abs(rect_size.x)
rect_size.y = abs(rect_size.y)
var had_rect_drag : bool = false
if rect_size.x > _rect_drag_min_ofset || rect_size.y > _rect_drag_min_ofset:
had_rect_drag = true
# Click
if !had_rect_drag:
# select vertex
var closest_idx : int = -1
var closest_dist : float = 1e10
for i in range(_handle_points.size()):
var vert_pos_3d : Vector3 = gt.xform(_handle_points[i])
var vert_pos_2d : Vector2 = camera.unproject_position(vert_pos_3d)
var dist_3d : float = ray_from.distance_to(vert_pos_3d)
var dist_2d : float = gpoint.distance_to(vert_pos_2d)
if (dist_2d < grab_threshold && dist_3d < closest_dist):
closest_dist = dist_3d
closest_idx = i
if (closest_idx >= 0):
for si in range(_selected_points.size()):
if _selected_points[si] == closest_idx:
if event.control:
_selected_points.remove(si)
return true
return false
if event.control:
return false
if event.shift:
_selected_points.append(closest_idx)
else:
# Select new point only
_selected_points.resize(0)
_selected_points.append(closest_idx)
apply()
redraw()
else:
# Don't unselect all if either control or shift is held down
if event.shift || event.control:
return false
if _selected_points.size() == 0:
return false
#Unselect all
_selected_points.resize(0)
redraw()
#Rect drag
else:
pass
else:
# event is pressed
_rect_drag = true
_rect_drag_start_point = event.get_position()
# elif event is InputEventMouseMotion: # elif event is InputEventMouseMotion:
# if edit_mode == EditMode.EDIT_MODE_NONE: # if edit_mode == EditMode.EDIT_MODE_NONE: