Proper rotation implementation.

This commit is contained in:
Relintai 2022-01-28 10:57:43 +01:00
parent 43b70b854e
commit f1a8188dfa

View File

@ -68,6 +68,7 @@ var _handle_drag_op : bool = false
var _drag_op_orig_verices : PoolVector3Array = PoolVector3Array() var _drag_op_orig_verices : PoolVector3Array = PoolVector3Array()
var _drag_op_indices : PoolIntArray = PoolIntArray() var _drag_op_indices : PoolIntArray = PoolIntArray()
var _drag_op_accumulator : Vector3 = Vector3() var _drag_op_accumulator : Vector3 = Vector3()
var _drag_op_accumulator_quat : Quat = Quat()
var _editor_plugin : EditorPlugin = null var _editor_plugin : EditorPlugin = null
var _undo_redo : UndoRedo = null var _undo_redo : UndoRedo = null
@ -96,6 +97,8 @@ func set_handle(index: int, camera: Camera, point: Vector2):
else: else:
_drag_op_accumulator = Vector3() _drag_op_accumulator = Vector3()
_drag_op_accumulator_quat = Quat()
_drag_op_orig_verices = copy_mdr_verts_array() _drag_op_orig_verices = copy_mdr_verts_array()
setup_op_drag_indices() setup_op_drag_indices()
@ -142,24 +145,15 @@ func set_handle(index: int, camera: Camera, point: Vector2):
apply() apply()
redraw() redraw()
elif edit_mode == EditMode.EDIT_MODE_ROTATE: elif edit_mode == EditMode.EDIT_MODE_ROTATE:
var ofs : Vector3 = Vector3() var yrot : Quat = Quat(Vector3(0, 1, 0), relative.x * 0.01)
var xrot : Quat = Quat(camera.get_global_transform().basis.x, relative.y * 0.01)
if (axis_constraint & AxisConstraint.X) != 0: _drag_op_accumulator_quat *= yrot
ofs.x = relative.x * 0.001 * sign(camera.get_global_transform().basis.z.z) _drag_op_accumulator_quat *= xrot
_drag_op_accumulator_quat = _drag_op_accumulator_quat.normalized()
if (axis_constraint & AxisConstraint.Y) != 0:
ofs.y = relative.y * -0.001 var b : Basis = Basis(_drag_op_accumulator_quat)
if (axis_constraint & AxisConstraint.Z) != 0:
ofs.z = relative.x * 0.001 * -sign(camera.get_global_transform().basis.z.x)
_drag_op_accumulator += ofs
_drag_op_accumulator = _drag_op_accumulator.normalized()
var b : Basis = Basis().rotated(Vector3(1, 0, 0), _drag_op_accumulator.x)
b = b.rotated(Vector3(0, 1, 0), _drag_op_accumulator.y)
b = b.rotated(Vector3(0, 0, 1), _drag_op_accumulator.z)
mul_all_selected_with_basis(b) mul_all_selected_with_basis(b)
apply() apply()
@ -167,10 +161,10 @@ func set_handle(index: int, camera: Camera, point: Vector2):
previous_point = point previous_point = point
func commit_handle(index: int, restore, cancel: bool = false) -> void: #func commit_handle(index: int, restore, cancel: bool = false) -> void:
previous_point = Vector2() # previous_point = Vector2()
#
print("MDR Editor: commit_handle test") # print("MDR Editor: commit_handle test")
func redraw(): func redraw():
clear() clear()