From 45a1f42e5189dc7b294fc922eb3b936f99279ca3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 23 Jan 2022 01:58:43 +0100 Subject: [PATCH] Transfer the current editing state from the active gizmo when a new mesh data instance is selected. Also smaller cleanups. --- .../addons/mesh_data_resource_editor/MDIEd.gd | 6 ++--- .../mesh_data_resource_editor/MIDGizmo.gd | 26 ++++++++++++------- .../mesh_data_resource_editor/plugin.gd | 24 ++++++++--------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/game/addons/mesh_data_resource_editor/MDIEd.gd b/game/addons/mesh_data_resource_editor/MDIEd.gd index bb1127fb..7aa3deff 100644 --- a/game/addons/mesh_data_resource_editor/MDIEd.gd +++ b/game/addons/mesh_data_resource_editor/MDIEd.gd @@ -77,17 +77,17 @@ func set_edit_mode_scale() -> void: func on_edit_mode_translate_toggled(on : bool) -> void: if on: if _plugin: - _plugin.set_translate(on) + _plugin.set_translate() func on_edit_mode_rotate_toggled(on : bool) -> void: if on: if _plugin: - _plugin.set_rotate(on) + _plugin.set_rotate() func on_edit_mode_scale_toggled(on : bool) -> void: if on: if _plugin: - _plugin.set_scale(on) + _plugin.set_scale() #axis locks func get_axis_x() -> bool: diff --git a/game/addons/mesh_data_resource_editor/MIDGizmo.gd b/game/addons/mesh_data_resource_editor/MIDGizmo.gd index fb3dd98c..eecb177c 100644 --- a/game/addons/mesh_data_resource_editor/MIDGizmo.gd +++ b/game/addons/mesh_data_resource_editor/MIDGizmo.gd @@ -287,18 +287,18 @@ func mul_all_selected_with_basis(b : Basis) -> void: v = b * v _vertices.set(j, v) -func set_translate(on : bool) -> void: - if on: - edit_mode = EditMode.EDIT_MODE_TRANSLATE +func set_translate() -> void: + edit_mode = EditMode.EDIT_MODE_TRANSLATE -func set_scale(on : bool) -> void: - if on: - edit_mode = EditMode.EDIT_MODE_SCALE - -func set_rotate(on : bool) -> void: - if on: - edit_mode = EditMode.EDIT_MODE_ROTATE +func set_scale() -> void: + edit_mode = EditMode.EDIT_MODE_SCALE +func set_rotate() -> void: + edit_mode = EditMode.EDIT_MODE_ROTATE + +func set_edit_mode(em : int) -> void: + edit_mode = em + func set_axis_x(on : bool) -> void: if on: axis_constraint |= AxisConstraint.X @@ -1233,3 +1233,9 @@ func set_pivot_mdi_origin(): func set_pivot_world_origin(): pivot_type = PivotTypes.PIVOT_TYPE_WORLD_ORIGIN + +func transfer_state_from(other) -> void: + edit_mode = other.edit_mode + pivot_type = other.pivot_type + axis_constraint = other.axis_constraint + selection_mode = other.selection_mode diff --git a/game/addons/mesh_data_resource_editor/plugin.gd b/game/addons/mesh_data_resource_editor/plugin.gd index d83824ba..6ad32303 100644 --- a/game/addons/mesh_data_resource_editor/plugin.gd +++ b/game/addons/mesh_data_resource_editor/plugin.gd @@ -14,8 +14,6 @@ var active_gizmos : Array var current_mesh_data_instance : MeshDataInstance = null func _enter_tree(): - #print("_enter_tree") - gizmo_plugin = MdiGizmoPlugin.new() mdi_ed_gui = MDIEdGui.instance() mdi_ed_gui.set_plugin(self) @@ -58,12 +56,15 @@ func handles(object): func edit(object): var mdi : MeshDataInstance = object as MeshDataInstance - - current_mesh_data_instance = mdi - + if mdi: + if current_mesh_data_instance && mdi.gizmo && current_mesh_data_instance.gizmo: + mdi.gizmo.transfer_state_from(current_mesh_data_instance.gizmo) + mdi_ed_gui.set_mesh_data_resource(mdi.mesh_data) mdi_ed_gui.set_mesh_data_instance(mdi) + + current_mesh_data_instance = mdi func make_visible(visible): #print("make_visible") @@ -91,17 +92,17 @@ func unregister_gizmo(gizmo): active_gizmos.remove(i) return -func set_translate(on : bool) -> void: +func set_translate() -> void: if current_mesh_data_instance && current_mesh_data_instance.gizmo: - current_mesh_data_instance.gizmo.set_translate(on) + current_mesh_data_instance.gizmo.set_translate() -func set_scale(on : bool) -> void: +func set_scale() -> void: if current_mesh_data_instance && current_mesh_data_instance.gizmo: - current_mesh_data_instance.gizmo.set_scale(on) + current_mesh_data_instance.gizmo.set_scale() -func set_rotate(on : bool) -> void: +func set_rotate() -> void: if current_mesh_data_instance && current_mesh_data_instance.gizmo: - current_mesh_data_instance.gizmo.set_rotate(on) + current_mesh_data_instance.gizmo.set_rotate() func set_axis_x(on : bool) -> void: if current_mesh_data_instance && current_mesh_data_instance.gizmo: @@ -119,7 +120,6 @@ func set_selection_mode_vertex() -> void: if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_selection_mode_vertex() - func set_selection_mode_edge() -> void: if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_selection_mode_edge()