From 7e05bda987348ca8149dd0f803fc15c1100ca9f7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 11 Feb 2022 17:29:37 +0100 Subject: [PATCH] Added a flip face action to mdr ed. --- .../addons/mesh_data_resource_editor/MDIEd.gd | 3 +++ .../mesh_data_resource_editor/MDIEd.tscn | 6 +++++ .../mesh_data_resource_editor/MIDGizmo.gd | 25 +++++++++++++++++++ .../mesh_data_resource_editor/plugin.gd | 4 +++ 4 files changed, 38 insertions(+) diff --git a/game/addons/mesh_data_resource_editor/MDIEd.gd b/game/addons/mesh_data_resource_editor/MDIEd.gd index eaa82744..60d8b2e2 100644 --- a/game/addons/mesh_data_resource_editor/MDIEd.gd +++ b/game/addons/mesh_data_resource_editor/MDIEd.gd @@ -250,3 +250,6 @@ func onhandle_selection_type_all_toggled(on : bool): func _on_clean_mesh_pressed(): _plugin.clean_mesh() + +func _on_flip_face_pressed(): + _plugin.flip_selected_faces() diff --git a/game/addons/mesh_data_resource_editor/MDIEd.tscn b/game/addons/mesh_data_resource_editor/MDIEd.tscn index 66e54f20..ad31b92a 100644 --- a/game/addons/mesh_data_resource_editor/MDIEd.tscn +++ b/game/addons/mesh_data_resource_editor/MDIEd.tscn @@ -540,6 +540,11 @@ margin_right = 1010.0 margin_bottom = 20.0 text = "Delete" +[node name="Flip" type="Button" parent="VBoxContainer/ScrollContainer/VBoxContainer2/FaceOps/Operations"] +margin_right = 1010.0 +margin_bottom = 20.0 +text = "Flip" + [node name="HSeparator4" type="HSeparator" parent="VBoxContainer/ScrollContainer/VBoxContainer2"] margin_top = 196.0 margin_right = 998.0 @@ -750,6 +755,7 @@ size_flags_vertical = 3 [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/EdgeOps/Operations/HBoxContainer/Mark" to="." method="_on_mark_seam_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/EdgeOps/Operations/HBoxContainer/Unmark" to="." method="_on_unmark_seam_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/FaceOps/Operations/Delete" to="." method="_on_delete_pressed"] +[connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/FaceOps/Operations/Flip" to="." method="_on_flip_face_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/GenNormals" to="." method="_on_GenNormals_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/GenTangents" to="." method="_on_GenTangents_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/RemDoubles" to="." method="_on_RemDoubles_pressed"] diff --git a/game/addons/mesh_data_resource_editor/MIDGizmo.gd b/game/addons/mesh_data_resource_editor/MIDGizmo.gd index 48b2f3bd..c1526957 100644 --- a/game/addons/mesh_data_resource_editor/MIDGizmo.gd +++ b/game/addons/mesh_data_resource_editor/MIDGizmo.gd @@ -1637,6 +1637,31 @@ func uv_unwrap() -> void: add_mesh_change_undo_redo(orig_arr, mdr_arr, "uv_unwrap") enable_change_event() +func flip_selected_faces() -> void: + if !_mdr: + return + + if _selected_points.size() == 0: + return + + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: + pass + elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: + pass + elif selection_mode == SelectionMode.SELECTION_MODE_FACE: + disable_change_event() + + var orig_arr = copy_arrays(_mdr.array) + + for sp in _selected_points: + var triangle_index : int = find_first_triangle_index_for_face(sp) + + MDRMeshUtils.flip_triangle_ti(_mdr, triangle_index) + + add_mesh_change_undo_redo(orig_arr, _mdr.array, "Flip Faces") + + enable_change_event() + func add_mesh_change_undo_redo(orig_arr : Array, new_arr : Array, action_name : String) -> void: _undo_redo.create_action(action_name) var nac : Array = copy_arrays(new_arr) diff --git a/game/addons/mesh_data_resource_editor/plugin.gd b/game/addons/mesh_data_resource_editor/plugin.gd index 8569be37..d733834c 100644 --- a/game/addons/mesh_data_resource_editor/plugin.gd +++ b/game/addons/mesh_data_resource_editor/plugin.gd @@ -280,3 +280,7 @@ func extrude(): func clean_mesh(): if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.clean_mesh() + +func flip_selected_faces(): + if current_mesh_data_instance && current_mesh_data_instance.gizmo: + current_mesh_data_instance.gizmo.flip_selected_faces()