diff --git a/modules/mesh_data_resource/editor/addon/MDIEd.gd b/modules/mesh_data_resource/editor/addon/MDIEd.gd deleted file mode 100644 index 60d8b2e28..000000000 --- a/modules/mesh_data_resource/editor/addon/MDIEd.gd +++ /dev/null @@ -1,255 +0,0 @@ -tool -extends Control - -var _plugin : EditorPlugin - -export var uv_preview_path : NodePath -export var uv_editor_path : NodePath - -var uv_preview : Node -var uv_editor : Node - -func _enter_tree(): - uv_preview = get_node(uv_preview_path) - uv_editor = get_node(uv_editor_path) - - if _plugin && uv_editor: - uv_editor.set_plugin(_plugin) - -func set_plugin(plugin : EditorPlugin) -> void: - _plugin = plugin - - if uv_editor: - uv_editor.set_plugin(plugin) - -func set_mesh_data_resource(a : MeshDataResource) -> void: - if uv_preview: - uv_preview.set_mesh_data_resource(a) - - if uv_editor: - uv_editor.set_mesh_data_resource(a) - -func set_mesh_data_instance(a : MeshDataInstance) -> void: - if uv_preview: - uv_preview.set_mesh_data_instance(a) - - if uv_editor: - uv_editor.set_mesh_data_instance(a) - -func _unhandled_key_input(event : InputEventKey) -> void: - if event.echo: - return - - if event.alt || event.shift || event.control || event.meta || event.command: - return - - if event.scancode == KEY_G: - set_edit_mode_translate() - elif event.scancode == KEY_H: - set_edit_mode_rotate() - elif event.scancode == KEY_J: - set_edit_mode_scale() - - elif event.scancode == KEY_V: - set_axis_x(!get_axis_x()) - elif event.scancode == KEY_B: - set_axis_y(!get_axis_y()) - elif event.scancode == KEY_N: - set_axis_z(!get_axis_z()) - - elif event.scancode == KEY_K: - set_selection_mode_vertex() - elif event.scancode == KEY_L: - set_selection_mode_edge() - elif event.scancode == KEY_SEMICOLON: - set_selection_mode_face() - -#Edit modes -func set_edit_mode_translate() -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer/Translate.pressed = true - -func set_edit_mode_rotate() -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer/Rotate.pressed = true - -func set_edit_mode_scale() -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer/Scale.pressed = true - -func on_edit_mode_translate_toggled(on : bool) -> void: - if on: - if _plugin: - _plugin.set_translate() - -func on_edit_mode_rotate_toggled(on : bool) -> void: - if on: - if _plugin: - _plugin.set_rotate() - -func on_edit_mode_scale_toggled(on : bool) -> void: - if on: - if _plugin: - _plugin.set_scale() - -#axis locks -func get_axis_x() -> bool: - return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisX.pressed - -func get_axis_y() -> bool: - return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisY.pressed - -func get_axis_z() -> bool: - return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisZ.pressed - -func set_axis_x(on : bool) -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisX.pressed = on - -func set_axis_y(on : bool) -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisY.pressed = on - -func set_axis_z(on : bool) -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisZ.pressed = on - -func on_axis_x_toggled(on : bool) -> void: - if _plugin: - _plugin.set_axis_x(on) - -func on_axis_y_toggled(on : bool) -> void: - if _plugin: - _plugin.set_axis_y(on) - -func on_axis_z_toggled(on : bool) -> void: - if _plugin: - _plugin.set_axis_z(on) - -#selection modes -func on_selection_mode_vertex_toggled(on : bool) -> void: - if on: - if _plugin: - _plugin.set_selection_mode_vertex() - -func on_selection_mode_edge_toggled(on : bool) -> void: - if on: - if _plugin: - _plugin.set_selection_mode_edge() - -func on_selection_mode_face_toggled(on : bool) -> void: - if on: - if _plugin: - _plugin.set_selection_mode_face() - -func set_selection_mode_vertex() -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer3/Vertex.pressed = true - -func set_selection_mode_edge() -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer3/Edge.pressed = true - -func set_selection_mode_face() -> void: - $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer3/Face.pressed = true - - -func _on_Extrude_pressed(): - _plugin.extrude() - -func _on_AddBox_pressed(): - _plugin.add_box() - -func _on_UnwrapButton_pressed(): - _plugin.uv_unwrap() - -func _on_add_triangle_pressed(): - _plugin.add_triangle() - -func _on_add_quad_pressed(): - _plugin.add_quad() - -func _on_split_pressed(): - _plugin.split() - -func _on_connect_to_first_selected_pressed(): - _plugin.connect_to_first_selected() - -func _on_connect_to_avg_pressed(): - _plugin.connect_to_avg() - -func _on_connect_to_last_selected_pressed(): - _plugin.connect_to_last_selected() - -func _on_disconnect_pressed(): - _plugin.disconnect_action() - -func _on_add_triangle_at_pressed(): - _plugin.add_triangle_at() - -func _on_add_auad_at_pressed(): - _plugin.add_quad_at() - -func _oncreate_face_pressed(): - _plugin.create_face() - -func _on_delete_pressed(): - _plugin.delete_selected() - -func _on_GenNormals_pressed(): - _plugin.generate_normals() - -func _on_RemDoubles_pressed(): - _plugin.remove_doubles() - -func _on_MergeOptimize_pressed(): - _plugin.merge_optimize() - -func _on_GenTangents_pressed(): - _plugin.generate_tangents() - -func _on_mark_seam_pressed(): - _plugin.mark_seam() - -func _on_unmark_seam_pressed(): - _plugin.unmark_seam() - -func _on_apply_seams_pressed(): - _plugin.apply_seam() - -func _on_uv_edit_pressed(): - $Popups/UVEditorPopup.popup_centered() - -func on_pivot_average_toggled(on : bool): - if on: - _plugin.set_pivot_averaged() - -func on_pivot_mdi_origin_toggled(on : bool): - if on: - _plugin.set_pivot_mdi_origin() - -func on_pivot_world_origin_toggled(on : bool): - if on: - _plugin.set_pivot_world_origin() - -func on_visual_indicator_outline_toggled(on : bool): - _plugin.visual_indicator_outline_set(on) - -func on_visual_indicator_seam_toggled(on : bool): - _plugin.visual_indicator_seam_set(on) - -func on_visual_indicator_handle_toggled(on : bool): - _plugin.visual_indicator_handle_set(on) - -func _on_select_all_pressed(): - _plugin.select_all() - -func onhandle_selection_type_front_toggled(on : bool): - if on: - _plugin.handle_selection_type_front() - -func onhandle_selection_type_back_toggled(on : bool): - if on: - _plugin.handle_selection_type_back() - -func onhandle_selection_type_all_toggled(on : bool): - if on: - _plugin.handle_selection_type_all() - -func _on_clean_mesh_pressed(): - _plugin.clean_mesh() - -func _on_flip_face_pressed(): - _plugin.flip_selected_faces() diff --git a/modules/mesh_data_resource/editor/addon/MDIGizmoPlugin.gd b/modules/mesh_data_resource/editor/addon/MDIGizmoPlugin.gd deleted file mode 100644 index 771e22dbd..000000000 --- a/modules/mesh_data_resource/editor/addon/MDIGizmoPlugin.gd +++ /dev/null @@ -1,33 +0,0 @@ -tool -extends EditorSpatialGizmoPlugin - -const MDIGizmo = preload("res://addons/mesh_data_resource_editor/MIDGizmo.gd") - -var plugin - -func _init(): - create_material("main", Color(0.7, 0.7, 0.7)) - create_material("seam", Color(1, 0, 0), false, true) - create_handle_material("handles") - -func get_name(): - return "MDIGizmo" - -func get_priority(): - return 100 - -func create_gizmo(spatial): - if spatial is MeshDataInstance: - var gizmo = MDIGizmo.new() - - gizmo.set_editor_plugin(plugin) - gizmo.set_spatial_node(spatial) - gizmo.setup() - plugin.register_gizmo(gizmo) - - return gizmo - else: - return null - -func is_handle_highlighted(gizmo, index): - pass diff --git a/modules/mesh_data_resource/editor/addon/plugin.cfg b/modules/mesh_data_resource/editor/addon/plugin.cfg deleted file mode 100644 index 8522bd0f5..000000000 --- a/modules/mesh_data_resource/editor/addon/plugin.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[plugin] - -name="mesh_data_resource_editor" -description="" -author="Relintai" -version="1.0" -script="plugin.gd" diff --git a/modules/mesh_data_resource/editor/addon/MDIEd.tscn b/modules/mesh_data_resource/editor/mdi_ed.cpp similarity index 78% rename from modules/mesh_data_resource/editor/addon/MDIEd.tscn rename to modules/mesh_data_resource/editor/mdi_ed.cpp index ad31b92aa..ab82dec6a 100644 --- a/modules/mesh_data_resource/editor/addon/MDIEd.tscn +++ b/modules/mesh_data_resource/editor/mdi_ed.cpp @@ -1,3 +1,405 @@ +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "mdi_ed.h" + +void MDIEd::_enter_tree() { + /* + uv_preview = get_node(uv_preview_path) + uv_editor = get_node(uv_editor_path) + + if _plugin && uv_editor: + uv_editor.set_plugin(_plugin) + */ +} +void MDIEd::set_plugin(EditorPlugin *plugin) { + /* + _plugin = plugin + + if uv_editor: + uv_editor.set_plugin(plugin) + */ +} +void MDIEd::set_mesh_data_resource(Ref a) { + /* + if uv_preview: + uv_preview.set_mesh_data_resource(a) + + if uv_editor: + uv_editor.set_mesh_data_resource(a) + */ +} +void MDIEd::set_mesh_data_instance(MeshDataInstance *a) { + /* + if uv_preview: + uv_preview.set_mesh_data_instance(a) + + if uv_editor: + uv_editor.set_mesh_data_instance(a) + */ +} +void MDIEd::_unhandled_key_input(Ref event) { + /* + if event.echo: + return + + if event.alt || event.shift || event.control || event.meta || event.command: + return + + if event.scancode == KEY_G: + set_edit_mode_translate() + elif event.scancode == KEY_H: + set_edit_mode_rotate() + elif event.scancode == KEY_J: + set_edit_mode_scale() + + elif event.scancode == KEY_V: + set_axis_x(!get_axis_x()) + elif event.scancode == KEY_B: + set_axis_y(!get_axis_y()) + elif event.scancode == KEY_N: + set_axis_z(!get_axis_z()) + + elif event.scancode == KEY_K: + set_selection_mode_vertex() + elif event.scancode == KEY_L: + set_selection_mode_edge() + elif event.scancode == KEY_SEMICOLON: + set_selection_mode_face() + + */ +} + +//Edit modes +void MDIEd::set_edit_mode_translate() { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer/Translate.pressed = true + */ +} +void MDIEd::set_edit_mode_rotate() { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer/Rotate.pressed = true + */ +} +void MDIEd::set_edit_mode_scale() { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer/Scale.pressed = true + */ +} + +void MDIEd::on_edit_mode_translate_toggled(bool on) { + /* + if on: + if _plugin: + _plugin.set_translate() + */ +} +void MDIEd::on_edit_mode_rotate_toggled(bool on) { + /* + if on: + if _plugin: + _plugin.set_rotate() + */ +} +void MDIEd::on_edit_mode_scale_toggled(bool on) { + /* + if on: + if _plugin: + _plugin.set_scale() + */ +} + +//axis locks +bool MDIEd::get_axis_x() { + /* + return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisX.pressed + */ +} +bool MDIEd::get_axis_y() { + /* + return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisY.pressed + */ +} +bool MDIEd::get_axis_z() { + /* + return $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisZ.pressed + */ +} +void MDIEd::set_axis_x(bool on) { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisX.pressed = on + */ +} +void MDIEd::set_axis_y(bool on) { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisY.pressed = on + */ +} +void MDIEd::set_axis_z(bool on) { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer2/AxisZ.pressed = on + */ +} + +void MDIEd::on_axis_x_toggled(bool on) { + /* + if _plugin: + _plugin.set_axis_x(on) + */ +} +void MDIEd::on_axis_y_toggled(bool on) { + /* + if _plugin: + _plugin.set_axis_y(on) + */ +} +void MDIEd::on_axis_z_toggled(bool on) { + /* + if _plugin: + _plugin.set_axis_z(on) + */ +} + +//selection modes +void MDIEd::on_selection_mode_vertex_toggled(bool on) { + /* + if on: + if _plugin: + _plugin.set_selection_mode_vertex() + */ +} +void MDIEd::on_selection_mode_edge_toggled(bool on) { + /* + if on: + if _plugin: + _plugin.set_selection_mode_edge() + */ +} +void MDIEd::on_selection_mode_face_toggled(bool on) { + /* + if on: + if _plugin: + _plugin.set_selection_mode_face() + */ +} + +void MDIEd::set_selection_mode_vertex() { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer3/Vertex.pressed = true + */ +} +void MDIEd::set_selection_mode_edge() { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer3/Edge.pressed = true + */ +} +void MDIEd::set_selection_mode_face() { + /* + $VBoxContainer/Actions/Actions/VBoxContainer2/HBoxContainer3/Face.pressed = true + */ +} + +void MDIEd::_on_Extrude_pressed() { + /* + _plugin.extrude() + */ +} +void MDIEd::_on_AddBox_pressed() { + /* + _plugin.add_box() + */ +} +void MDIEd::_on_UnwrapButton_pressed() { + /* + _plugin.uv_unwrap() + */ +} +void MDIEd::_on_add_triangle_pressed() { + /* + _plugin.add_triangle() + */ +} +void MDIEd::_on_add_quad_pressed() { + /* + _plugin.add_quad() + */ +} +void MDIEd::_on_split_pressed() { + /* + _plugin.split() + */ +} +void MDIEd::_on_connect_to_first_selected_pressed() { + /* + _plugin.connect_to_first_selected() + */ +} +void MDIEd::_on_connect_to_avg_pressed() { + /* + _plugin.connect_to_avg() + */ +} +void MDIEd::_on_connect_to_last_selected_pressed() { + /* + _plugin.connect_to_last_selected() + */ +} +void MDIEd::_on_disconnect_pressed() { + /* + _plugin.disconnect_action() + */ +} +void MDIEd::_on_add_triangle_at_pressed() { + /* + _plugin.add_triangle_at() + */ +} +void MDIEd::_on_add_auad_at_pressed() { + /* + _plugin.add_quad_at() + */ +} +void MDIEd::_oncreate_face_pressed() { + /* + _plugin.create_face() + */ +} +void MDIEd::_on_delete_pressed() { + /* + _plugin.delete_selected() + */ +} +void MDIEd::_on_GenNormals_pressed() { + /* + _plugin.generate_normals() + */ +} +void MDIEd::_on_RemDoubles_pressed() { + /* + _plugin.remove_doubles() + */ +} +void MDIEd::_on_MergeOptimize_pressed() { + /* + _plugin.merge_optimize() + */ +} +void MDIEd::_on_GenTangents_pressed() { + /* + _plugin.generate_tangents() + */ +} +void MDIEd::_on_mark_seam_pressed() { + /* + _plugin.mark_seam() + */ +} +void MDIEd::_on_unmark_seam_pressed() { + /* + _plugin.unmark_seam() + */ +} +void MDIEd::_on_apply_seams_pressed() { + /* + _plugin.apply_seam() + */ +} +void MDIEd::_on_uv_edit_pressed() { + /* + $Popups/UVEditorPopup.popup_centered() + */ +} + +void MDIEd::on_pivot_average_toggled(bool on) { + /* + if on: + _plugin.set_pivot_averaged() + */ +} +void MDIEd::on_pivot_mdi_origin_toggled(bool on) { + /* + if on: + _plugin.set_pivot_mdi_origin() + */ +} +void MDIEd::on_pivot_world_origin_toggled(bool on) { + /* + if on: + _plugin.set_pivot_world_origin() + */ +} +void MDIEd::on_visual_indicator_outline_toggled(bool on) { + /* + _plugin.visual_indicator_outline_set(on) + */ +} +void MDIEd::on_visual_indicator_seam_toggled(bool on) { + /* + _plugin.visual_indicator_seam_set(on) + */ +} +void MDIEd::on_visual_indicator_handle_toggled(bool on) { + /* + _plugin.visual_indicator_handle_set(on) + */ +} +void MDIEd::_on_select_all_pressed() { + /* + _plugin.select_all() + */ +} + +void MDIEd::onhandle_selection_type_front_toggled(bool on) { + /* + if on: + _plugin.handle_selection_type_front() + */ +} +void MDIEd::onhandle_selection_type_back_toggled(bool on) { + /* + if on: + _plugin.handle_selection_type_back() + */ +} +void MDIEd::onhandle_selection_type_all_toggled(bool on) { + /* + if on: + _plugin.handle_selection_type_all() + */ +} + +void MDIEd::_on_clean_mesh_pressed() { + /* + _plugin.clean_mesh() + */ +} +void MDIEd::_on_flip_face_pressed() { + /* + _plugin.flip_selected_faces() + */ +} + +MDIEd::MDIEd() { + /* [gd_scene load_steps=9 format=2] [ext_resource path="res://addons/mesh_data_resource_editor/MDIEd.gd" type="Script" id=1] @@ -238,7 +640,7 @@ margin_left = 343.0 margin_right = 668.0 margin_bottom = 20.0 rect_min_size = Vector2( 25, 20 ) -hint_tooltip = "Only select handles that face away +hint_tooltip = "Only select handles that face away the camera." size_flags_horizontal = 3 toggle_mode = true @@ -767,3 +1169,13 @@ size_flags_vertical = 3 [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/Add/Add/AddBox" to="." method="_on_AddBox_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/Add/Add/AddTriangle" to="." method="_on_add_triangle_pressed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxContainer2/Add/Add/AddQuad" to="." method="_on_add_quad_pressed"] + + + */ +} + +MDIEd::~MDIEd() { +} + +void MDIEd::_bind_methods() { +} diff --git a/modules/mesh_data_resource/editor/mdi_ed.h b/modules/mesh_data_resource/editor/mdi_ed.h new file mode 100644 index 000000000..8f81e80a2 --- /dev/null +++ b/modules/mesh_data_resource/editor/mdi_ed.h @@ -0,0 +1,121 @@ +#ifndef MDI_ED_H +#define MDI_ED_H + +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/control.h" + +class MDIEd : public Control { + GDCLASS(MDIEd, Control); + +public: + void _enter_tree(); + void set_plugin(EditorPlugin *plugin); + void set_mesh_data_resource(Ref a); + void set_mesh_data_instance(MeshDataInstance *a); + void _unhandled_key_input(Ref event); + + //Edit modes + void set_edit_mode_translate(); + void set_edit_mode_rotate(); + void set_edit_mode_scale(); + + void on_edit_mode_translate_toggled(bool on); + void on_edit_mode_rotate_toggled(bool on); + void on_edit_mode_scale_toggled(bool on); + + //axis locks + bool get_axis_x(); + bool get_axis_y(); + bool get_axis_z(); + void set_axis_x(bool on); + void set_axis_y(bool on); + void set_axis_z(bool on); + + void on_axis_x_toggled(bool on); + void on_axis_y_toggled(bool on); + void on_axis_z_toggled(bool on); + + //selection modes + void on_selection_mode_vertex_toggled(bool on); + void on_selection_mode_edge_toggled(bool on); + void on_selection_mode_face_toggled(bool on); + + void set_selection_mode_vertex(); + void set_selection_mode_edge(); + void set_selection_mode_face(); + + void _on_Extrude_pressed(); + void _on_AddBox_pressed(); + void _on_UnwrapButton_pressed(); + void _on_add_triangle_pressed(); + void _on_add_quad_pressed(); + void _on_split_pressed(); + void _on_connect_to_first_selected_pressed(); + void _on_connect_to_avg_pressed(); + void _on_connect_to_last_selected_pressed(); + void _on_disconnect_pressed(); + void _on_add_triangle_at_pressed(); + void _on_add_auad_at_pressed(); + void _oncreate_face_pressed(); + void _on_delete_pressed(); + void _on_GenNormals_pressed(); + void _on_RemDoubles_pressed(); + void _on_MergeOptimize_pressed(); + void _on_GenTangents_pressed(); + void _on_mark_seam_pressed(); + void _on_unmark_seam_pressed(); + void _on_apply_seams_pressed(); + void _on_uv_edit_pressed(); + + void on_pivot_average_toggled(bool on); + void on_pivot_mdi_origin_toggled(bool on); + void on_pivot_world_origin_toggled(bool on); + void on_visual_indicator_outline_toggled(bool on); + void on_visual_indicator_seam_toggled(bool on); + void on_visual_indicator_handle_toggled(bool on); + void _on_select_all_pressed(); + + void onhandle_selection_type_front_toggled(bool on); + void onhandle_selection_type_back_toggled(bool on); + void onhandle_selection_type_all_toggled(bool on); + + void _on_clean_mesh_pressed(); + void _on_flip_face_pressed(); + + MDIEd(); + ~MDIEd(); + + EditorPlugin *_plugin; + + //export var uv_preview_path : NodePath + //export var uv_editor_path : NodePath + + Node *uv_preview; + Node *uv_editor; + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/modules/mesh_data_resource/editor/addon/plugin.gd b/modules/mesh_data_resource/editor/mdi_ed_plugin.cpp similarity index 61% rename from modules/mesh_data_resource/editor/addon/plugin.gd rename to modules/mesh_data_resource/editor/mdi_ed_plugin.cpp index ebfa3ac1d..d52929e9e 100644 --- a/modules/mesh_data_resource/editor/addon/plugin.gd +++ b/modules/mesh_data_resource/editor/mdi_ed_plugin.cpp @@ -1,289 +1,431 @@ -tool -extends EditorPlugin +/* +Copyright (c) 2019-2022 Péter Magyar -const MDRMeshUtils = preload("res://addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd") +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -const MdiGizmoPlugin = preload("res://addons/mesh_data_resource_editor/MDIGizmoPlugin.gd") -const MDIEdGui = preload("res://addons/mesh_data_resource_editor/MDIEd.tscn") +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -var gizmo_plugin = MdiGizmoPlugin.new() -var mdi_ed_gui : Control +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ -var active_gizmos : Array +#include "mdi_ed_plugin.h" -var current_mesh_data_instance : MeshDataInstance = null -func _enter_tree(): +void MDIEdPlugin::_enter_tree() { + /* gizmo_plugin = MdiGizmoPlugin.new() mdi_ed_gui = MDIEdGui.instance() mdi_ed_gui.set_plugin(self) active_gizmos = [] - + gizmo_plugin.plugin = self - + add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui) mdi_ed_gui.hide() - - add_spatial_gizmo_plugin(gizmo_plugin) - - set_input_event_forwarding_always_enabled() -func _exit_tree(): + add_spatial_gizmo_plugin(gizmo_plugin) + + set_input_event_forwarding_always_enabled() + */ +} +void MDIEdPlugin::_exit_tree() { + /* #print("_exit_tree") - + remove_spatial_gizmo_plugin(gizmo_plugin) #remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui) mdi_ed_gui.queue_free() pass - -#func enable_plugin(): -# print("enable_plugin") -# pass -# -#func disable_plugin(): -# print("disable_plugin") -# remove_spatial_gizmo_plugin(gizmo_plugin) -# remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui) -# mdi_ed_gui.queue_free() + */ +} -func handles(object): +bool MDIEdPlugin::handles(Object *object) { + /* #print("disable_plugin") - + if object is MeshDataInstance: return true - - return false -func edit(object): + return false + */ +} +void MDIEdPlugin::edit(Object *object) { + /* var mdi : MeshDataInstance = object as MeshDataInstance 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): + current_mesh_data_instance = mdi + */ +} +void MDIEdPlugin::make_visible(bool visible) { + /* #print("make_visible") - + if visible: mdi_ed_gui.show() else: #mdi_ed_gui.hide() #figure out how to hide it when something else gets selected, don't hide on unselect pass + */ +} -func get_plugin_name(): +void MDIEdPlugin::get_plugin_name() { + /* return "mesh_data_resource_editor" - + */ +} -#func forward_spatial_gui_input(camera, event): -# return forward_spatial_gui_input(0, camera, event) - -func register_gizmo(gizmo): - active_gizmos.append(gizmo) - -func unregister_gizmo(gizmo): +void MDIEdPlugin::register_gizmo(MDIGizmo *gizmo) { + /* +active_gizmos.append(gizmo) + */ +} +void MDIEdPlugin::unregister_gizmo(MDIGizmo *gizmo) { + /* for i in range(active_gizmos.size()): if active_gizmos[i] == gizmo: active_gizmos.remove(i) return + */ +} -func set_translate() -> void: +void MDIEdPlugin::set_translate() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_translate() - -func set_scale() -> void: + */ +} +void MDIEdPlugin::set_scale() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_scale() - -func set_rotate() -> void: + */ +} +void MDIEdPlugin::set_rotate() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_rotate() - -func set_axis_x(on : bool) -> void: + */ +} + +void MDIEdPlugin::set_axis_x(bool on) { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_axis_x(on) - -func set_axis_y(on : bool) -> void: + */ +} +void MDIEdPlugin::set_axis_y(bool on) { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_axis_y(on) - -func set_axis_z(on : bool) -> void: + */ +} +void MDIEdPlugin::set_axis_z(bool on) { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_axis_z(on) + */ +} -func set_selection_mode_vertex() -> void: +void MDIEdPlugin::set_selection_mode_vertex() { + /* 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: + */ +} +void MDIEdPlugin::set_selection_mode_edge() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_selection_mode_edge() - -func set_selection_mode_face() -> void: + */ +} +void MDIEdPlugin::set_selection_mode_face() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_selection_mode_face() + */ +} -func get_mdr() -> MeshDataResource: +Ref MDIEdPlugin::get_mdr() { + /* if current_mesh_data_instance: return current_mesh_data_instance.mesh_data - + return null + */ +} - -#func forward_spatial_gui_input(camera, event): -# for g in active_gizmos: -# if g.forward_spatial_gui_input(0, camera, event): -# return true -# -# return false - -func forward_spatial_gui_input(index, camera, event): +bool MDIEdPlugin::forward_spatial_gui_input(int index, Camera *camera, const Ref &p_event) { + /* if (!is_instance_valid(current_mesh_data_instance)): current_mesh_data_instance = null - + if current_mesh_data_instance && current_mesh_data_instance.gizmo: if current_mesh_data_instance.gizmo.forward_spatial_gui_input(index, camera, event): return true return false + */ +} -func add_box() -> void: +void MDIEdPlugin::add_box() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.add_box() - -func add_triangle() -> void: + */ +} +void MDIEdPlugin::add_triangle() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.add_triangle() - -func add_quad() -> void: + */ +} +void MDIEdPlugin::add_quad() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.add_quad() + */ +} -func add_triangle_at() -> void: +void MDIEdPlugin::add_triangle_at() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.add_triangle_at() - -func add_quad_at() -> void: + */ +} +void MDIEdPlugin::add_quad_at() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.add_quad_at() + */ +} -func split(): +void MDIEdPlugin::split() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.split() + */ +} -func connect_action(): +void MDIEdPlugin::connect_action() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.connect_action() - -func disconnect_action(): + */ +} +void MDIEdPlugin::disconnect_action() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.disconnect_action() + */ +} -func create_face(): +void MDIEdPlugin::create_face() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.create_face() - -func delete_selected(): + */ +} +void MDIEdPlugin::delete_selected() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.delete_selected() + */ +} -func generate_normals(): +void MDIEdPlugin::generate_normals() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.generate_normals() - -func remove_doubles(): + */ +} +void MDIEdPlugin::remove_doubles() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.remove_doubles() - -func merge_optimize(): + */ +} +void MDIEdPlugin::merge_optimize() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.merge_optimize() - -func generate_tangents(): + */ +} +void MDIEdPlugin::generate_tangents() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.generate_tangents() - -func connect_to_first_selected(): + */ +} + +void MDIEdPlugin::connect_to_first_selected() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.connect_to_first_selected() - -func connect_to_avg(): + */ +} +void MDIEdPlugin::connect_to_avg() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.connect_to_avg() - -func connect_to_last_selected(): + */ +} +void MDIEdPlugin::connect_to_last_selected() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.connect_to_last_selected() + */ +} -func mark_seam(): +void MDIEdPlugin::mark_seam() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.mark_seam() - -func unmark_seam(): + */ +} +void MDIEdPlugin::unmark_seam() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.unmark_seam() - -func apply_seam(): + */ +} +void MDIEdPlugin::apply_seam() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.apply_seam() + */ +} -func uv_unwrap() -> void: +void MDIEdPlugin::uv_unwrap() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.uv_unwrap() - -func set_pivot_averaged(): + */ +} + +void MDIEdPlugin::set_pivot_averaged() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_pivot_averaged() - -func set_pivot_mdi_origin(): + */ +} +void MDIEdPlugin::set_pivot_mdi_origin() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_pivot_mdi_origin() - -func set_pivot_world_origin(): + */ +} +void MDIEdPlugin::set_pivot_world_origin() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.set_pivot_world_origin() - -func visual_indicator_outline_set(on : bool): + */ +} + +void MDIEdPlugin::visual_indicator_outline_set(bool on) { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.visual_indicator_outline_set(on) - -func visual_indicator_seam_set(on : bool): + */ +} +void MDIEdPlugin::visual_indicator_seam_set(bool on) { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.visual_indicator_seam_set(on) - -func visual_indicator_handle_set(on : bool): + */ +} +void MDIEdPlugin::visual_indicator_handle_set(bool on) { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.visual_indicator_handle_set(on) + */ +} -func select_all(): +void MDIEdPlugin::select_all() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.select_all() + */ +} -func handle_selection_type_front(): +void MDIEdPlugin::handle_selection_type_front() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.handle_selection_type_front() - -func handle_selection_type_back(): + */ +} +void MDIEdPlugin::handle_selection_type_back() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.handle_selection_type_back() - -func handle_selection_type_all(): + */ +} +void MDIEdPlugin::handle_selection_type_all() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.handle_selection_type_all() + */ +} -func extrude(): +void MDIEdPlugin::extrude() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.extrude() - -func clean_mesh(): + */ +} +void MDIEdPlugin::clean_mesh() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.clean_mesh() - -func flip_selected_faces(): + */ +} + +void MDIEdPlugin::flip_selected_faces() { + /* if current_mesh_data_instance && current_mesh_data_instance.gizmo: current_mesh_data_instance.gizmo.flip_selected_faces() + */ +} + +MDIEdPlugin::MDIEdPlugin() { + /* + + const MDRMeshUtils = preload("res://addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd") + + const MdiGizmoPlugin = preload("res://addons/mesh_data_resource_editor/MDIGizmoPlugin.gd") + const MDIEdGui = preload("res://addons/mesh_data_resource_editor/MDIEd.tscn") + + var gizmo_plugin = MdiGizmoPlugin.new() + var mdi_ed_gui : Control + + var active_gizmos : Array + + var current_mesh_data_instance : MeshDataInstance = null + + */ +} + +MDIEdPlugin::~MDIEdPlugin() { +} + +void MDIEdPlugin::_bind_methods() { +} diff --git a/modules/mesh_data_resource/editor/mdi_ed_plugin.h b/modules/mesh_data_resource/editor/mdi_ed_plugin.h new file mode 100644 index 000000000..fac2c4a63 --- /dev/null +++ b/modules/mesh_data_resource/editor/mdi_ed_plugin.h @@ -0,0 +1,131 @@ +#ifndef MDI_ED_PLUGIN_H +#define MDI_ED_PLUGIN_H + +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "editor/editor_plugin.h" + +#include "core/os/input_event.h" + +class Camera; +class MDIGizmo; +class MeshDataResource; +class MdiGizmoPlugin; +class MeshDataInstance; + +class MDIEdPlugin : public EditorPlugin { + GDCLASS(MDIEdPlugin, EditorPlugin); + +public: + void _enter_tree(); + void _exit_tree(); + + bool handles(Object *object); + void edit(Object *object); + void make_visible(bool visible); + + void get_plugin_name(); + + void register_gizmo(MDIGizmo *gizmo); + void unregister_gizmo(MDIGizmo *gizmo); + + void set_translate(); + void set_scale(); + void set_rotate(); + + void set_axis_x(bool on); + void set_axis_y(bool on); + void set_axis_z(bool on); + + void set_selection_mode_vertex(); + void set_selection_mode_edge(); + void set_selection_mode_face(); + + Ref get_mdr(); + + bool forward_spatial_gui_input(int index, Camera *camera, const Ref &p_event); + + void add_box(); + void add_triangle(); + void add_quad(); + + void add_triangle_at(); + void add_quad_at(); + + void split(); + + void connect_action(); + void disconnect_action(); + + void create_face(); + void delete_selected(); + + void generate_normals(); + void remove_doubles(); + void merge_optimize(); + void generate_tangents(); + + void connect_to_first_selected(); + void connect_to_avg(); + void connect_to_last_selected(); + + void mark_seam(); + void unmark_seam(); + void apply_seam(); + + void uv_unwrap(); + + void set_pivot_averaged(); + void set_pivot_mdi_origin(); + void set_pivot_world_origin(); + + void visual_indicator_outline_set(bool on); + void visual_indicator_seam_set(bool on); + void visual_indicator_handle_set(bool on); + + void select_all(); + + void handle_selection_type_front(); + void handle_selection_type_back(); + void handle_selection_type_all(); + + void extrude(); + void clean_mesh(); + + void flip_selected_faces(); + + MDIEdPlugin(); + ~MDIEdPlugin(); + + MdiGizmoPlugin *gizmo_plugin; + Control mdi_ed_gui; + + Array active_gizmos; + + Ref current_mesh_data_instance; + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/modules/mesh_data_resource/editor/addon/MIDGizmo.gd b/modules/mesh_data_resource/editor/mdi_gizmo.cpp similarity index 84% rename from modules/mesh_data_resource/editor/addon/MIDGizmo.gd rename to modules/mesh_data_resource/editor/mdi_gizmo.cpp index ac229ef9d..3548856ed 100644 --- a/modules/mesh_data_resource/editor/addon/MIDGizmo.gd +++ b/modules/mesh_data_resource/editor/mdi_gizmo.cpp @@ -1,109 +1,60 @@ -tool -extends EditorSpatialGizmo +/* +Copyright (c) 2019-2022 Péter Magyar -var MeshOutline = preload("res://addons/mesh_data_resource_editor/utilities/mesh_outline.gd") -var MeshDecompose = preload("res://addons/mesh_data_resource_editor/utilities/mesh_decompose.gd") -var MDRMeshUtils = preload("res://addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd") +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -enum EditMode { - EDIT_MODE_NONE = 0, - EDIT_MODE_TRANSLATE = 1, - EDIT_MODE_SCALE = 2, - EDIT_MODE_ROTATE = 3 -} +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -enum AxisConstraint { - X = 1 << 0, - Y = 1 << 1, - Z = 1 << 2, -} +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ -enum SelectionMode { - SELECTION_MODE_VERTEX = 0, - SELECTION_MODE_EDGE = 1, - SELECTION_MODE_FACE = 2, -} +#include "mdi_gizmo.h" -enum PivotTypes { - PIVOT_TYPE_AVERAGED = 0, - PIVOT_TYPE_MDI_ORIGIN = 1, - PIVOT_TYPE_WORLD_ORIGIN = 2, -} - -enum HandleSelectionType { - HANDLE_SELECTION_TYPE_FRONT = 0, - HANDLE_SELECTION_TYPE_BACK = 1, - HANDLE_SELECTION_TYPE_ALL = 2, -} - -var gizmo_size = 3.0 - -var edit_mode : int = EditMode.EDIT_MODE_TRANSLATE -var pivot_type : int = PivotTypes.PIVOT_TYPE_AVERAGED -var axis_constraint : int = AxisConstraint.X | AxisConstraint.Y | AxisConstraint.Z -var selection_mode : int = SelectionMode.SELECTION_MODE_VERTEX -var handle_selection_type : int = HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT -var visual_indicator_outline : bool = true -var visual_indicator_seam : bool= true -var visual_indicator_handle : bool = true - -var previous_point : Vector2 -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 _vertices : PoolVector3Array -var _indices : PoolIntArray -var _handle_points : PoolVector3Array -var _handle_to_vertex_map : Array -var _selected_points : PoolIntArray - -var _mesh_outline_generator - -var _handle_drag_op : bool = false -var _drag_op_orig_verices : PoolVector3Array = PoolVector3Array() -var _drag_op_indices : PoolIntArray = PoolIntArray() -var _drag_op_accumulator : Vector3 = Vector3() -var _drag_op_accumulator_quat : Quat = Quat() -var _drag_op_pivot : Vector3 = Vector3() - -var _editor_plugin : EditorPlugin = null -var _undo_redo : UndoRedo = null - -func _init(): - _mesh_outline_generator = MeshOutline.new() - -func setup() -> void: +void MDIGizmo::setup() { + /* get_spatial_node().connect("mesh_data_resource_changed", self, "on_mesh_data_resource_changed") on_mesh_data_resource_changed(get_spatial_node().mesh_data) - -func set_editor_plugin(editor_plugin : EditorPlugin) -> void: + */ +} +void MDIGizmo::set_editor_plugin(EditorPlugin *editor_plugin) { + /* _editor_plugin = editor_plugin - - _undo_redo = _editor_plugin.get_undo_redo() -func set_handle(index: int, camera: Camera, point: Vector2): + _undo_redo = _editor_plugin.get_undo_redo() + */ +} + +void MDIGizmo::set_handle(int index, Camera *camera, Vector2 point) { + /* var relative : Vector2 = point - previous_point - + if !_handle_drag_op: relative = Vector2() _handle_drag_op = true - + if edit_mode == EditMode.EDIT_MODE_SCALE: _drag_op_accumulator = Vector3(1, 1, 1) else: _drag_op_accumulator = Vector3() - + _drag_op_accumulator_quat = Quat() - + _drag_op_orig_verices = copy_mdr_verts_array() setup_op_drag_indices() _drag_op_pivot = get_drag_op_pivot() - + if edit_mode == EditMode.EDIT_MODE_NONE: return elif edit_mode == EditMode.EDIT_MODE_TRANSLATE: @@ -115,40 +66,40 @@ func set_handle(index: int, camera: Camera, point: Vector2): ofs.x *= relative.x * 0.01 else: ofs.x = 0 - + if (axis_constraint & AxisConstraint.Y) != 0: ofs.y = relative.y * -0.01 else: ofs.y = 0 - + if (axis_constraint & AxisConstraint.Z) != 0: ofs.z *= relative.x * 0.01 else: ofs.z = 0 _drag_op_accumulator += ofs - + add_to_all_selected(_drag_op_accumulator) apply() redraw() elif edit_mode == EditMode.EDIT_MODE_SCALE: var r : float = ((relative.x + relative.y) * 0.05) - + var vs : Vector3 = Vector3() - + if (axis_constraint & AxisConstraint.X) != 0: vs.x = r - + if (axis_constraint & AxisConstraint.Y) != 0: vs.y = r - + if (axis_constraint & AxisConstraint.Z) != 0: vs.z = r - + _drag_op_accumulator += vs - - var b : Basis = Basis().scaled(_drag_op_accumulator) + + var b : Basis = Basis().scaled(_drag_op_accumulator) var t : Transform = Transform(Basis(), _drag_op_pivot) t *= Transform(b, Vector3()) t *= Transform(Basis(), _drag_op_pivot).inverse() @@ -174,91 +125,97 @@ func set_handle(index: int, camera: Camera, point: Vector2): apply() redraw() - + previous_point = point - -#func commit_handle(index: int, restore, cancel: bool = false) -> void: -# previous_point = Vector2() -# -# print("MDR Editor: commit_handle test") - -func redraw(): + */ +} +void MDIGizmo::redraw() { + /* clear() - + if !_mdr: return - + if _mdr.array.size() != ArrayMesh.ARRAY_MAX: return - + if !get_plugin(): return - + var handles_material : SpatialMaterial = get_plugin().get_material("handles", self) var material = get_plugin().get_material("main", self) var seam_material = get_plugin().get_material("seam", self) - + _mesh_outline_generator.setup(_mdr) - + if selection_mode == SelectionMode.SELECTION_MODE_EDGE: _mesh_outline_generator.generate_mark_edges(visual_indicator_outline, visual_indicator_handle) elif selection_mode == SelectionMode.SELECTION_MODE_FACE: _mesh_outline_generator.generate_mark_faces(visual_indicator_outline, visual_indicator_handle) else: _mesh_outline_generator.generate(visual_indicator_outline, visual_indicator_handle) - + if visual_indicator_outline || visual_indicator_handle: add_lines(_mesh_outline_generator.lines, material, false) - + if visual_indicator_seam: add_lines(_mesh_outline_generator.seam_lines, seam_material, false) - + if _selected_points.size() > 0: var vs : PoolVector3Array = PoolVector3Array() - + for i in _selected_points: vs.append(_handle_points[i]) - - add_handles(vs, handles_material) -func apply() -> void: + add_handles(vs, handles_material) + */ +} +void MDIGizmo::apply() { + /* if !_mdr: return - + disable_change_event() - + var arrs : Array = _mdr.array arrs[ArrayMesh.ARRAY_VERTEX] = _vertices arrs[ArrayMesh.ARRAY_INDEX] = _indices _mdr.array = arrs - - enable_change_event() -func select_all() -> void: + enable_change_event() + */ +} + +void MDIGizmo::select_all() { + /* if _selected_points.size() == _handle_points.size(): return - + _selected_points.resize(_handle_points.size()) - + for i in range(_selected_points.size()): _selected_points[i] = i - + redraw() + */ +} - -func selection_click(index, camera, event) -> bool: +bool MDIGizmo::selection_click(int index, Camera *camera, const Ref &event) { + /* if handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT: return selection_click_select_front_or_back(index, camera, event) elif handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_BACK: return selection_click_select_front_or_back(index, camera, event) else: return selection_click_select_through(index, camera, event) - - return false -func is_point_visible(point_orig : Vector3, camera_pos : Vector3, gt : Transform) -> bool: + return false + */ +} +bool MDIGizmo::is_point_visible(Vector3 point_orig, Vector3 camera_pos, Transform gt) { + /* var point : Vector3 = gt.xform(point_orig) - + # go from the given point to the origin (camera_pos -> camera) var dir : Vector3 = camera_pos - point dir = dir.normalized() @@ -269,24 +226,27 @@ func is_point_visible(point_orig : Vector3, camera_pos : Vector3, gt : Transform var i0 : int = _indices[i] var i1 : int = _indices[i + 1] var i2 : int = _indices[i + 2] - + var v0 : Vector3 = _vertices[i0] var v1 : Vector3 = _vertices[i1] var v2 : Vector3 = _vertices[i2] - + v0 = gt.xform(v0) v1 = gt.xform(v1) v2 = gt.xform(v2) - + var res = Geometry.ray_intersects_triangle(point, dir, v0, v1, v2) if res is Vector3: return false - + return true + */ +} -func selection_click_select_front_or_back(index, camera, event): +void MDIGizmo::selection_click_select_front_or_back(int index, Camera *camera, const Ref &event) { + /* var gt : Transform = get_spatial_node().global_transform var ray_from : Vector3 = camera.global_transform.origin var gpoint : Vector2 = event.get_position() @@ -295,7 +255,7 @@ func selection_click_select_front_or_back(index, camera, event): # 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) @@ -304,14 +264,14 @@ func selection_click_select_front_or_back(index, camera, event): if (dist_2d < grab_threshold && dist_3d < closest_dist): var point_visible : bool = is_point_visible(_handle_points[i], ray_from, gt) - + if handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT: if !point_visible: continue elif handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_BACK: if point_visible: continue - + closest_dist = dist_3d closest_idx = i @@ -321,12 +281,12 @@ func selection_click_select_front_or_back(index, camera, event): if event.alt || event.control: _selected_points.remove(si) return true - + return false - + if event.alt || event.control: return false - + if event.shift: _selected_points.append(closest_idx) else: @@ -340,16 +300,18 @@ func selection_click_select_front_or_back(index, camera, event): # Don't unselect all if either control or shift is held down if event.shift || event.control || event.alt: return false - + if _selected_points.size() == 0: return false - + #Unselect all _selected_points.resize(0) redraw() - -func selection_click_select_through(index, camera, event): + */ +} +void MDIGizmo::selection_click_select_through(int index, Camera *camera, const Ref &event) { + /* var gt : Transform = get_spatial_node().global_transform var ray_from : Vector3 = camera.global_transform.origin var gpoint : Vector2 = event.get_position() @@ -358,30 +320,30 @@ func selection_click_select_through(index, camera, event): # 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.alt || event.control: _selected_points.remove(si) return true - + return false - + if event.alt || event.control: return false - + if event.shift: _selected_points.append(closest_idx) else: @@ -395,61 +357,65 @@ func selection_click_select_through(index, camera, event): # Don't unselect all if either control or shift is held down if event.shift || event.control || event.alt: return false - + if _selected_points.size() == 0: return false - + #Unselect all _selected_points.resize(0) redraw() - -func selection_drag(index, camera, event) -> void: + */ +} +void MDIGizmo::selection_drag(int index, Camera *camera, const Ref &event) { + /* if handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT: selection_drag_rect_select_front_back(index, camera, event) elif handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_BACK: selection_drag_rect_select_front_back(index, camera, event) else: selection_drag_rect_select_through(index, camera, event) - -func selection_drag_rect_select_front_back(index, camera, event): + */ +} +void MDIGizmo::selection_drag_rect_select_front_back(int index, Camera *camera, const Ref &event) { + /* var gt : Transform = get_spatial_node().global_transform var ray_from : Vector3 = camera.global_transform.origin - + 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 rect : Rect2 = Rect2(_rect_drag_start_point, rect_size) - + # This is needed so selection works even when you drag from bottom to top, and from right to left var rect_ofs : Vector2 = _rect_drag_start_point - mouse_pos - + if rect_ofs.x > 0: rect.position.x -= rect_ofs.x - + if rect_ofs.y > 0: rect.position.y -= rect_ofs.y - + var selected : PoolIntArray = PoolIntArray() - + 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) - + if rect.has_point(vert_pos_2d): var point_visible : bool = is_point_visible(_handle_points[i], ray_from, gt) - + if handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT: if !point_visible: continue elif handle_selection_type == HandleSelectionType.HANDLE_SELECTION_TYPE_BACK: if point_visible: continue - + selected.push_back(i) - + if event.alt || event.control: for isel in selected: for i in range(_selected_points.size()): @@ -457,50 +423,52 @@ func selection_drag_rect_select_front_back(index, camera, event): _selected_points.remove(i) break redraw() - + return - + if event.shift: for isel in selected: if !pool_int_arr_contains(_selected_points, isel): _selected_points.push_back(isel) - + redraw() return - + _selected_points.resize(0) _selected_points.append_array(selected) - - redraw() -func selection_drag_rect_select_through(index, camera, event): + redraw() + */ +} +void MDIGizmo::selection_drag_rect_select_through(int index, Camera *camera, const Ref &event) { + /* var gt : Transform = get_spatial_node().global_transform - + 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 rect : Rect2 = Rect2(_rect_drag_start_point, rect_size) - + # This is needed so selection works even when you drag from bottom to top, and from right to left var rect_ofs : Vector2 = _rect_drag_start_point - mouse_pos - + if rect_ofs.x > 0: rect.position.x -= rect_ofs.x - + if rect_ofs.y > 0: rect.position.y -= rect_ofs.y - + var selected : PoolIntArray = PoolIntArray() - + 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) - + if rect.has_point(vert_pos_2d): selected.push_back(i) - + if event.alt || event.control: for isel in selected: for i in range(_selected_points.size()): @@ -508,42 +476,44 @@ func selection_drag_rect_select_through(index, camera, event): _selected_points.remove(i) break redraw() - + return - + if event.shift: for isel in selected: if !pool_int_arr_contains(_selected_points, isel): _selected_points.push_back(isel) - + redraw() return - + _selected_points.resize(0) _selected_points.append_array(selected) - - redraw() -func forward_spatial_gui_input(index, camera, event): + redraw() + */ +} +bool MDIGizmo::forward_spatial_gui_input(int index, Camera *camera, const Ref &event) { + /* _last_known_camera_facing = camera.transform.basis.xform(Vector3(0, 0, -1)) - + if event is InputEventMouseButton: if event.get_button_index() == BUTTON_LEFT: if _handle_drag_op: if !event.is_pressed(): _handle_drag_op = false - + # If a handle was being dragged only run these if _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null && _mdr.array[ArrayMesh.ARRAY_VERTEX].size() == _drag_op_orig_verices.size(): _undo_redo.create_action("Drag") _undo_redo.add_do_method(self, "apply_vertex_array", _mdr, _mdr.array[ArrayMesh.ARRAY_VERTEX]) _undo_redo.add_undo_method(self, "apply_vertex_array", _mdr, _drag_op_orig_verices) _undo_redo.commit_action() - - # Dont consume the event here, because the handles will get stuck + + # Dont consume the event here, because the handles will get stuck # to the mouse pointer if we return true return false - + if !event.is_pressed(): # See whether we should check for a click or a selection box var mouse_pos : Vector2 = event.get_position() @@ -554,7 +524,7 @@ func forward_spatial_gui_input(index, camera, event): if rect_size.x > _rect_drag_min_ofset || rect_size.y > _rect_drag_min_ofset: had_rect_drag = true - + if !had_rect_drag: return selection_click(index, camera, event) else: @@ -568,203 +538,259 @@ func forward_spatial_gui_input(index, camera, event): return false -func add_to_all_selected(ofs : Vector3) -> void: + */ +} +void MDIGizmo::add_to_all_selected(Vector3 ofs) { + /* for i in _selected_points: var v : Vector3 = _handle_points[i] v += ofs _handle_points.set(i, v) - + for indx in _drag_op_indices: var v : Vector3 = _drag_op_orig_verices[indx] v += ofs _vertices.set(indx, v) + */ +} -func mul_all_selected_with_basis(b : Basis) -> void: +void MDIGizmo::mul_all_selected_with_basis(Basis b) { + /* for i in _selected_points: var v : Vector3 = _handle_points[i] v = b * v _handle_points.set(i, v) - + for indx in _drag_op_indices: var v : Vector3 = _drag_op_orig_verices[indx] v = b * v _vertices.set(indx, v) - -func mul_all_selected_with_transform(t : Transform) -> void: + */ +} +void MDIGizmo::mul_all_selected_with_transform(Transform t) { + /* for i in _selected_points: var v : Vector3 = _handle_points[i] v = t * v _handle_points.set(i, v) - + for indx in _drag_op_indices: var v : Vector3 = _drag_op_orig_verices[indx] v = t * v _vertices.set(indx, v) - -func mul_all_selected_with_transform_acc(t : Transform) -> void: + */ +} +void MDIGizmo::mul_all_selected_with_transform_acc(Transform t) { + /* for i in _selected_points: var v : Vector3 = _handle_points[i] v = t * v _handle_points.set(i, v) - + for indx in _drag_op_indices: var v : Vector3 = _vertices[indx] v = t * v _vertices.set(indx, v) + */ +} -func set_translate() -> void: +void MDIGizmo::set_translate() { + /* edit_mode = EditMode.EDIT_MODE_TRANSLATE - -func set_scale() -> void: + */ +} +void MDIGizmo::set_scale() { + /* edit_mode = EditMode.EDIT_MODE_SCALE - -func set_rotate() -> void: + */ +} +void MDIGizmo::set_rotate() { + /* edit_mode = EditMode.EDIT_MODE_ROTATE - -func set_edit_mode(em : int) -> void: + */ +} +void MDIGizmo::set_edit_mode(int em) { + /* edit_mode = em + */ +} -func set_axis_x(on : bool) -> void: +void MDIGizmo::set_axis_x(bool on) { + /* if on: axis_constraint |= AxisConstraint.X else: if (axis_constraint & AxisConstraint.X) != 0: axis_constraint ^= AxisConstraint.X - -func set_axis_y(on : bool) -> void: + */ +} +void MDIGizmo::set_axis_y(bool on) { + /* if on: axis_constraint |= AxisConstraint.Y else: if (axis_constraint & AxisConstraint.Y) != 0: axis_constraint ^= AxisConstraint.Y - -func set_axis_z(on : bool) -> void: + */ +} +void MDIGizmo::set_axis_z(bool on) { + /* if on: axis_constraint |= AxisConstraint.Z else: if (axis_constraint & AxisConstraint.Z) != 0: axis_constraint ^= AxisConstraint.Z + */ +} -func set_selection_mode_vertex() -> void: +void MDIGizmo::set_selection_mode_vertex() { + /* if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: return - + selection_mode = SelectionMode.SELECTION_MODE_VERTEX _selected_points.resize(0) recalculate_handle_points() redraw() - -func set_selection_mode_edge() -> void: + */ +} +void MDIGizmo::set_selection_mode_edge() { + /* if selection_mode == SelectionMode.SELECTION_MODE_EDGE: return - + selection_mode = SelectionMode.SELECTION_MODE_EDGE _selected_points.resize(0) recalculate_handle_points() redraw() - -func set_selection_mode_face() -> void: + */ +} +void MDIGizmo::set_selection_mode_face() { + /* if selection_mode == SelectionMode.SELECTION_MODE_FACE: return - + selection_mode = SelectionMode.SELECTION_MODE_FACE _selected_points.resize(0) recalculate_handle_points() redraw() + */ +} -func _notification(what): +void MDIGizmo::_notification(int what) { + /* if what == NOTIFICATION_PREDELETE: if self != null && get_plugin(): get_plugin().unregister_gizmo(self) + */ +} -func recalculate_handle_points() -> void: +void MDIGizmo::recalculate_handle_points() { + /* if !_mdr: _handle_points.resize(0) _handle_to_vertex_map.resize(0) return - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: _handle_points.resize(0) _handle_to_vertex_map.resize(0) return - + var arr : Array = Array() arr.resize(ArrayMesh.ARRAY_MAX) arr[ArrayMesh.ARRAY_VERTEX] = mdr_arr[ArrayMesh.ARRAY_VERTEX] arr[ArrayMesh.ARRAY_INDEX] = mdr_arr[ArrayMesh.ARRAY_INDEX] - + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: var merged_arrays : Array = MeshUtils.merge_mesh_array(arr) _handle_points = merged_arrays[ArrayMesh.ARRAY_VERTEX] _handle_to_vertex_map = MeshDecompose.get_handle_vertex_to_vertex_map(mdr_arr, _handle_points) elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: var result : Array = MeshDecompose.get_handle_edge_to_vertex_map(arr) - + _handle_points = result[0] _handle_to_vertex_map = result[1] elif selection_mode == SelectionMode.SELECTION_MODE_FACE: var result : Array = MeshDecompose.get_handle_face_to_vertex_map(arr) - + _handle_points = result[0] _handle_to_vertex_map = result[1] - -func on_mesh_data_resource_changed(mdr : MeshDataResource) -> void: + */ +} +void MDIGizmo::on_mesh_data_resource_changed(Ref mdr) { + /* if _mdr: _mdr.disconnect("changed", self, "on_mdr_changed") - + _mdr = mdr - + if _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null: _vertices = _mdr.array[ArrayMesh.ARRAY_VERTEX] _indices = _mdr.array[ArrayMesh.ARRAY_INDEX] else: _vertices.resize(0) _indices.resize(0) - + if _mdr: _mdr.connect("changed", self, "on_mdr_changed") - + recalculate_handle_points() redraw() - -func on_mdr_changed() -> void: + */ +} +void MDIGizmo::on_mdr_changed() { + /* if _mdr && _mdr.array.size() == ArrayMesh.ARRAY_MAX && _mdr.array[ArrayMesh.ARRAY_VERTEX] != null: _vertices = _mdr.array[ArrayMesh.ARRAY_VERTEX] _indices = _mdr.array[ArrayMesh.ARRAY_INDEX] else: _vertices.resize(0) _indices.resize(0) - + recalculate_handle_points() redraw() - -func disable_change_event() -> void: + */ +} +void MDIGizmo::disable_change_event() { + /* _mdr.disconnect("changed", self, "on_mdr_changed") - -func enable_change_event(update : bool = true) -> void: + */ +} +void MDIGizmo::enable_change_event(bool update = true) { + /* _mdr.connect("changed", self, "on_mdr_changed") - + if update: on_mdr_changed() - -func add_triangle() -> void: + */ +} +void MDIGizmo::add_triangle() { + /* if _mdr: var orig_arr = copy_arrays(_mdr.array) MDRMeshUtils.add_triangle(_mdr) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Triangle") - -func add_quad() -> void: + */ +} +void MDIGizmo::add_quad() { + /* if _mdr: var orig_arr = copy_arrays(_mdr.array) MDRMeshUtils.add_quad(_mdr) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Quad") + */ +} -func is_verts_equal(v0 : Vector3, v1 : Vector3) -> bool: +bool MDIGizmo::is_verts_equal(Vector3 v0, Vector3 v1) { + /* return is_equal_approx(v0.x, v1.x) && is_equal_approx(v0.y, v1.y) && is_equal_approx(v0.z, v1.z) - -func find_other_vertex_for_edge(edge : int, v0 : Vector3) -> Vector3: + */ +} +Vector3 find_other_vertex_for_edge(int edge, Vector3 v0) { + /* var ps : PoolIntArray = _handle_to_vertex_map[edge] var vert : Vector3 = Vector3() @@ -774,17 +800,19 @@ func find_other_vertex_for_edge(edge : int, v0 : Vector3) -> Vector3: if !is_verts_equal(v0, vert): return vert - - return v0 -func split_edge_indices(edge : int) -> Array: + return v0 + */ +} +Array MDIGizmo::MDIGizmo::split_edge_indices(int edge) { + /* var ps : PoolIntArray = _handle_to_vertex_map[edge] - + if ps.size() == 0: return [ ] var v0 : Vector3 = _vertices[ps[0]] - + var v0ei : PoolIntArray = PoolIntArray() v0ei.append(ps[0]) var v1ei : PoolIntArray = PoolIntArray() @@ -796,81 +824,89 @@ func split_edge_indices(edge : int) -> Array: v0ei.append(ps[i]) else: v1ei.append(ps[i]) - - return [ v0ei, v1ei ] -func pool_int_arr_contains(arr : PoolIntArray, val : int) -> bool: + return [ v0ei, v1ei ] + */ +} +bool MDIGizmo::pool_int_arr_contains(PoolIntArray arr, int val) { + /* for a in arr: if a == val: return true - - return false - -func find_triangles_for_edge(edge : int) -> PoolIntArray: + return false + */ +} +PoolIntArray MDIGizmo::find_triangles_for_edge(int edge) { + /* var eisarr : Array = split_edge_indices(edge) - + if eisarr.size() == 0: return PoolIntArray() - + # these should have the same size var v0ei : PoolIntArray = eisarr[0] var v1ei : PoolIntArray = eisarr[1] - + var res : PoolIntArray = PoolIntArray() - + for i in range(0, _indices.size(), 3): var i0 : int = _indices[i] var i1 : int = _indices[i + 1] var i2 : int = _indices[i + 2] - + if pool_int_arr_contains(v0ei, i0) || pool_int_arr_contains(v0ei, i1) || pool_int_arr_contains(v0ei, i2): if pool_int_arr_contains(v1ei, i0) || pool_int_arr_contains(v1ei, i1) || pool_int_arr_contains(v1ei, i2): res.append(i / 3) - - return res -func find_first_triangle_for_edge(edge : int) -> int: + return res + */ +} +int MDIGizmo::find_first_triangle_for_edge(int edge) { + /* var eisarr : Array = split_edge_indices(edge) if eisarr.size() == 0: return -1 - + # these should have the same size var v0ei : PoolIntArray = eisarr[0] var v1ei : PoolIntArray = eisarr[1] - + var res : PoolIntArray = PoolIntArray() - + for i in range(0, _indices.size(), 3): var i0 : int = _indices[i] var i1 : int = _indices[i + 1] var i2 : int = _indices[i + 2] - + if pool_int_arr_contains(v0ei, i0) || pool_int_arr_contains(v0ei, i1) || pool_int_arr_contains(v0ei, i2): if pool_int_arr_contains(v1ei, i0) || pool_int_arr_contains(v1ei, i1) || pool_int_arr_contains(v1ei, i2): return i / 3 - + return -1 -func add_triangle_to_edge(edge : int) -> void: + */ +} +void MDIGizmo::add_triangle_to_edge(int edge) { + /* var triangle_index : int = find_first_triangle_for_edge(edge) - + var inds : int = triangle_index * 3 - + var ti0 : int = _indices[inds] var ti1 : int = _indices[inds + 1] var ti2 : int = _indices[inds + 2] - + var ps : PoolIntArray = _handle_to_vertex_map[edge] - + if ps.size() == 0: return - + var ei0 : int = 0 var ei1 : int = 0 var erefind : int = 0 - + if !pool_int_arr_contains(ps, ti0): ei0 = ti1 ei1 = ti2 @@ -883,35 +919,38 @@ func add_triangle_to_edge(edge : int) -> void: ei0 = ti0 ei1 = ti1 erefind = ti2 - + var fo : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ti0], _vertices[ti1], _vertices[ti2]) var fn : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ei0], _vertices[ei1], _vertices[erefind]) - + if fo.dot(fn) < 0: var t : int = ei0 ei0 = ei1 ei1 = t - + MDRMeshUtils.append_triangle_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind]) -func add_quad_to_edge(edge : int) -> void: + */ +} +void MDIGizmo::add_quad_to_edge(int edge) { + /* var triangle_index : int = find_first_triangle_for_edge(edge) - + var inds : int = triangle_index * 3 - + var ti0 : int = _indices[inds] var ti1 : int = _indices[inds + 1] var ti2 : int = _indices[inds + 2] - + var ps : PoolIntArray = _handle_to_vertex_map[edge] - + if ps.size() == 0: return - + var ei0 : int = 0 var ei1 : int = 0 var erefind : int = 0 - + if !pool_int_arr_contains(ps, ti0): ei0 = ti1 ei1 = ti2 @@ -924,194 +963,206 @@ func add_quad_to_edge(edge : int) -> void: ei0 = ti0 ei1 = ti1 erefind = ti2 - + var fo : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ti0], _vertices[ti1], _vertices[ti2]) var fn : Vector3 = MDRMeshUtils.get_face_normal(_vertices[ei0], _vertices[ei1], _vertices[erefind]) - + if fo.dot(fn) < 0: var t : int = ei0 ei0 = ei1 ei1 = t - - MDRMeshUtils.append_quad_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind]) -func add_triangle_at() -> void: + MDRMeshUtils.append_quad_to_tri_edge(_mdr, _vertices[ei0], _vertices[ei1], _vertices[erefind]) + */ +} +void MDIGizmo::add_triangle_at() { + /* if !_mdr: return - + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: #todo pass elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: disable_change_event() var orig_arr = copy_arrays(_mdr.array) - + for sp in _selected_points: add_triangle_to_edge(sp) - + _selected_points.resize(0) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Triangle At") enable_change_event() else: add_triangle() - -func add_quad_at() -> void: + */ +} +void MDIGizmo::add_quad_at() { + /* if !_mdr: return - + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: #todo pass elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: disable_change_event() var orig_arr = copy_arrays(_mdr.array) - + for sp in _selected_points: add_quad_to_edge(sp) - + _selected_points.resize(0) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Quad At") enable_change_event() else: add_quad() + */ +} -func extrude() -> void: +void MDIGizmo::extrude() { + /* if !_mdr: return - + if _mdr.array.size() != ArrayMesh.ARRAY_MAX || _mdr.array[ArrayMesh.ARRAY_VERTEX] == null: return - + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: pass elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: disable_change_event() var orig_arr = copy_arrays(_mdr.array) var original_size : int = orig_arr[ArrayMesh.ARRAY_VERTEX].size() - + for sp in _selected_points: add_quad_to_edge(sp) var arr : Array = _mdr.array - + # Note: This algorithm depends heavily depends on the inner workings of add_quad_to_edge! var new_verts : PoolVector3Array = arr[ArrayMesh.ARRAY_VERTEX] - + # every 4 vertex is a quad # 1 ---- 2 # | | # | | # 0 ---- 3 # vertex 1, and 2 are the created new ones, 0, and 3 are duplicated from the original edge - + # Don't reallocate it every time var found_verts : PoolIntArray = PoolIntArray() - + # Go through every new created 0th vertex for i in range(original_size, new_verts.size(), 4): var v0 : Vector3 = new_verts[i] - + found_verts.resize(0) - + # Find a pair for it (has to be the 3th). for j in range(original_size, new_verts.size(), 4): if i == j: continue - + # +3 offset to 3rd vert var v3 : Vector3 = new_verts[j + 3] if is_verts_equal(v0, v3): # +2 offset to 2rd vert found_verts.append(j + 2) - + if found_verts.size() == 0: continue - + # Also append the first vertex index to simplify logic found_verts.append(i + 1) - + # Calculate avg var vavg : Vector3 = Vector3() for ind in found_verts: vavg += new_verts[ind] - + vavg /= found_verts.size() - + # set back for ind in found_verts: new_verts[ind] = vavg arr[ArrayMesh.ARRAY_VERTEX] = new_verts _mdr.array = arr - + _selected_points.resize(0) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Extrude") enable_change_event() - + # The selection alo will take care of the duplicates var new_handle_points : PoolVector3Array = PoolVector3Array() for i in range(original_size, new_verts.size(), 4): var vavg : Vector3 = new_verts[i + 1] vavg += new_verts[i + 2] vavg /= 2 - + new_handle_points.append(vavg) - + select_handle_points(new_handle_points) else: add_quad() - -func add_box() -> void: + */ +} +void MDIGizmo::add_box() { + /* if _mdr: var orig_arr = copy_arrays(_mdr.array) MDRMeshUtils.add_box(_mdr) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Add Box") - -func split(): - pass - -func disconnect_action(): - pass - -func get_first_triangle_index_for_vertex(indx : int) -> int: + */ +} +void MDIGizmo::split() { +} +void MDIGizmo::disconnect_action() { +} +int MDIGizmo::get_first_triangle_index_for_vertex(int indx) { + /* for i in range(_indices.size()): if _indices[i] == indx: return i / 3 - + return -1 - -func create_face(): + */ +} + +void MDIGizmo::create_face() { + /* if !_mdr: return - + if _selected_points.size() <= 2: return if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: disable_change_event() - + var orig_arr = copy_arrays(_mdr.array) - + var points : PoolVector3Array = PoolVector3Array() - + for sp in _selected_points: points.push_back(_handle_points[sp]) - + if points.size() == 3: var i0 : int = _handle_to_vertex_map[_selected_points[0]][0] var i1 : int = _handle_to_vertex_map[_selected_points[1]][0] var i2 : int = _handle_to_vertex_map[_selected_points[2]][0] - + var v0 : Vector3 = points[0] var v1 : Vector3 = points[1] var v2 : Vector3 = points[2] - + var tfn : Vector3 = Vector3() - + if orig_arr[ArrayMesh.ARRAY_NORMAL] != null && orig_arr[ArrayMesh.ARRAY_NORMAL].size() == orig_arr[ArrayMesh.ARRAY_VERTEX].size(): var normals : PoolVector3Array = orig_arr[ArrayMesh.ARRAY_NORMAL] - + tfn += normals[i0] tfn += normals[i1] tfn += normals[i2] @@ -1121,35 +1172,38 @@ func create_face(): tfn = MDRMeshUtils.get_face_normal(_vertices[i0], _vertices[i1], _vertices[i2]) var flip : bool = !MDRMeshUtils.should_triangle_flip(v0, v1, v2, tfn) - + MDRMeshUtils.add_triangle_at(_mdr, v0, v1, v2, flip) add_mesh_change_undo_redo(orig_arr, _mdr.array, "Create Face") enable_change_event() return - + if !MDRMeshUtils.add_triangulated_mesh_from_points_delaunay(_mdr, points, _last_known_camera_facing): enable_change_event() return - + add_mesh_change_undo_redo(orig_arr, _mdr.array, "Create Face") - + #_selected_points.resize(0) enable_change_event() elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: pass elif selection_mode == SelectionMode.SELECTION_MODE_FACE: pass + */ +} -func split_face_indices(face : int) -> Array: +Array MDIGizmo::split_face_indices(int face) { + /* var ps : PoolIntArray = _handle_to_vertex_map[face] - + if ps.size() == 0: return [ ] var v0 : Vector3 = _vertices[ps[0]] var v1 : Vector3 = Vector3() var v1found : bool = false - + var v0ei : PoolIntArray = PoolIntArray() v0ei.append(ps[0]) var v1ei : PoolIntArray = PoolIntArray() @@ -1170,39 +1224,44 @@ func split_face_indices(face : int) -> Array: v1found = true v1 = _vertices[ps[i]] v1ei.append(ps[i]) - - return [ v0ei, v1ei, v2ei ] -func find_first_triangle_index_for_face(face : int) -> int: + return [ v0ei, v1ei, v2ei ] + */ +} +int MDIGizmo::find_first_triangle_index_for_face(int face) { + /* var split_indices_arr : Array = split_face_indices(face) - + if split_indices_arr.size() == 0: return -1 - + var v0ei : PoolIntArray = split_indices_arr[0] var v1ei : PoolIntArray = split_indices_arr[1] var v2ei : PoolIntArray = split_indices_arr[2] var tri_index : int = -1 - + for i in range(0, _indices.size(), 3): var i0 : int = _indices[i] var i1 : int = _indices[i + 1] var i2 : int = _indices[i + 2] - + if pool_int_arr_contains(v0ei, i0) || pool_int_arr_contains(v0ei, i1) || pool_int_arr_contains(v0ei, i2): if pool_int_arr_contains(v1ei, i0) || pool_int_arr_contains(v1ei, i1) || pool_int_arr_contains(v1ei, i2): if pool_int_arr_contains(v2ei, i0) || pool_int_arr_contains(v2ei, i1) || pool_int_arr_contains(v2ei, i2): return i / 3 - - return -1 -func delete_selected() -> void: + return -1 + */ +} + +void MDIGizmo::delete_selected() { + /* if !_mdr: return - + if _selected_points.size() == 0: return - + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: #todo pass @@ -1211,14 +1270,14 @@ func delete_selected() -> void: pass elif selection_mode == SelectionMode.SELECTION_MODE_FACE: disable_change_event() - + var orig_arr = copy_arrays(_mdr.array) - + var triangle_indexes : Array = Array() for sp in _selected_points: var triangle_index : int = find_first_triangle_index_for_face(sp) triangle_indexes.append(triangle_index) - + #delete in reverse triangle index order triangle_indexes.sort() @@ -1230,296 +1289,319 @@ func delete_selected() -> void: _selected_points.resize(0) enable_change_event() - -func generate_normals(): + */ +} +void MDIGizmo::generate_normals() { + /* if !_mdr: return var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() var orig_arr = copy_arrays(_mdr.array) var orig_seams = copy_pool_int_array(_mdr.seams) - + var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr) MDRMeshUtils.generate_normals_mdr(_mdr) MDRMeshUtils.points_to_seams(_mdr, seam_points) - + add_mesh_seam_change_undo_redo(orig_arr, orig_seams, _mdr.array, _mdr.seams, "Generate Normals") enable_change_event() - -func generate_tangents(): + */ +} +void MDIGizmo::generate_tangents() { + /* if !_mdr: return - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() var orig_arr = copy_arrays(_mdr.array) var orig_seams = copy_pool_int_array(_mdr.seams) - + var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr) MDRMeshUtils.generate_tangents(_mdr) MDRMeshUtils.points_to_seams(_mdr, seam_points) - + add_mesh_seam_change_undo_redo(orig_arr, orig_seams, _mdr.array, _mdr.seams, "Generate Tangents") enable_change_event() - -func remove_doubles(): + */ +} +void MDIGizmo::remove_doubles() { + /* if !_mdr: return - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() var orig_arr = copy_arrays(_mdr.array) var orig_seams = copy_pool_int_array(_mdr.seams) - + var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr) - + var merged_arrays : Array = MeshUtils.remove_doubles(mdr_arr) _mdr.array = merged_arrays MDRMeshUtils.points_to_seams(_mdr, seam_points) - + add_mesh_seam_change_undo_redo(orig_arr, orig_seams, _mdr.array, _mdr.seams, "Remove Doubles") enable_change_event() - -func merge_optimize(): + */ +} +void MDIGizmo::merge_optimize() { + /* if !_mdr: return - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() var orig_arr = copy_arrays(_mdr.array) var orig_seams = copy_pool_int_array(_mdr.seams) - + var seam_points : PoolVector3Array = MDRMeshUtils.seams_to_points(_mdr) - + var merged_arrays : Array = MeshUtils.merge_mesh_array(mdr_arr) _mdr.array = merged_arrays MDRMeshUtils.points_to_seams(_mdr, seam_points) - + add_mesh_seam_change_undo_redo(orig_arr, orig_seams, _mdr.array, _mdr.seams, "Merge Optimize") enable_change_event() - -func connect_to_first_selected(): + + */ +} + +void MDIGizmo::connect_to_first_selected() { + /* if !_mdr: return - + if _selected_points.size() < 2: return - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() - + var orig_arr = copy_arrays(_mdr.array) - + var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX] if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: var mpos : Vector3 = _handle_points[_selected_points[0]] - + for i in range(1, _selected_points.size()): var ps : PoolIntArray = _handle_to_vertex_map[_selected_points[i]] - + for indx in ps: vertices[indx] = mpos - + _selected_points.resize(0) - + mdr_arr[ArrayMesh.ARRAY_VERTEX] = vertices _mdr.array = mdr_arr - + add_mesh_change_undo_redo(orig_arr, _mdr.array, "Connect to first selected") enable_change_event() elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: pass elif selection_mode == SelectionMode.SELECTION_MODE_FACE: pass - -func connect_to_avg(): + */ +} +void MDIGizmo::connect_to_avg() { + /* if !_mdr: return - + if _selected_points.size() < 2: return - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() var orig_arr = copy_arrays(_mdr.array) - + var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX] if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: var mpos : Vector3 = Vector3() - + for sp in _selected_points: mpos += _handle_points[sp] - + mpos /= _selected_points.size() - + for i in range(_selected_points.size()): var ps : PoolIntArray = _handle_to_vertex_map[_selected_points[i]] - + for indx in ps: vertices[indx] = mpos - + _selected_points.resize(0) - + mdr_arr[ArrayMesh.ARRAY_VERTEX] = vertices _mdr.array = mdr_arr - + add_mesh_change_undo_redo(orig_arr, _mdr.array, "Connect to average") enable_change_event() - + elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: pass elif selection_mode == SelectionMode.SELECTION_MODE_FACE: pass - -func connect_to_last_selected(): + */ +} +void MDIGizmo::connect_to_last_selected() { + /* if !_mdr: return - + if _selected_points.size() < 2: return - + var orig_arr = copy_arrays(_mdr.array) - + var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() - + var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX] if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: var mpos : Vector3 = _handle_points[_selected_points[_selected_points.size() - 1]] - + for i in range(0, _selected_points.size() - 1): var ps : PoolIntArray = _handle_to_vertex_map[_selected_points[i]] - + for indx in ps: vertices[indx] = mpos - + _selected_points.resize(0) - + mdr_arr[ArrayMesh.ARRAY_VERTEX] = vertices _mdr.array = mdr_arr - + add_mesh_change_undo_redo(orig_arr, _mdr.array, "Connect to last selected") enable_change_event() elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: pass elif selection_mode == SelectionMode.SELECTION_MODE_FACE: pass + */ +} -func get_first_index_pair_for_edge(edge : int) -> PoolIntArray: +PoolIntArray MDIGizmo::get_first_index_pair_for_edge(int edge) { + /* var ret : PoolIntArray = PoolIntArray() - + var eisarr : Array = split_edge_indices(edge) if eisarr.size() == 0: return ret - + # these should have the same size var v0ei : PoolIntArray = eisarr[0] var v1ei : PoolIntArray = eisarr[1] - + var res : PoolIntArray = PoolIntArray() - + for i in range(0, _indices.size(), 3): var i0 : int = _indices[i] var i1 : int = _indices[i + 1] var i2 : int = _indices[i + 2] - + if pool_int_arr_contains(v0ei, i0) || pool_int_arr_contains(v0ei, i1) || pool_int_arr_contains(v0ei, i2): if pool_int_arr_contains(v1ei, i0) || pool_int_arr_contains(v1ei, i1) || pool_int_arr_contains(v1ei, i2): - + if pool_int_arr_contains(v0ei, i0): ret.push_back(i0) elif pool_int_arr_contains(v0ei, i1): ret.push_back(i1) elif pool_int_arr_contains(v0ei, i2): ret.push_back(i2) - + if pool_int_arr_contains(v1ei, i0): ret.push_back(i0) elif pool_int_arr_contains(v1ei, i1): ret.push_back(i1) elif pool_int_arr_contains(v1ei, i2): ret.push_back(i2) - + return ret - - return ret -func get_all_index_pairs_for_edge(edge : int) -> PoolIntArray: + return ret + */ +} +PoolIntArray MDIGizmo::get_all_index_pairs_for_edge(int edge) { + /* var ret : PoolIntArray = PoolIntArray() - + var eisarr : Array = split_edge_indices(edge) if eisarr.size() == 0: return ret - + # these should have the same size var v0ei : PoolIntArray = eisarr[0] var v1ei : PoolIntArray = eisarr[1] - + var res : PoolIntArray = PoolIntArray() - + for i in range(0, _indices.size(), 3): var i0 : int = _indices[i] var i1 : int = _indices[i + 1] var i2 : int = _indices[i + 2] - + if pool_int_arr_contains(v0ei, i0) || pool_int_arr_contains(v0ei, i1) || pool_int_arr_contains(v0ei, i2): if pool_int_arr_contains(v1ei, i0) || pool_int_arr_contains(v1ei, i1) || pool_int_arr_contains(v1ei, i2): - + if pool_int_arr_contains(v0ei, i0): ret.push_back(i0) elif pool_int_arr_contains(v0ei, i1): ret.push_back(i1) elif pool_int_arr_contains(v0ei, i2): ret.push_back(i2) - + if pool_int_arr_contains(v1ei, i0): ret.push_back(i0) elif pool_int_arr_contains(v1ei, i1): ret.push_back(i1) elif pool_int_arr_contains(v1ei, i2): ret.push_back(i2) - + return ret + */ +} - -func mark_seam(): +void MDIGizmo::mark_seam() { + /* if !_mdr: return - + if _selected_points.size() == 0: return @@ -1527,231 +1609,267 @@ func mark_seam(): pass elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: disable_change_event() - + var prev_seams : PoolIntArray = copy_pool_int_array(_mdr.seams) - + for se in _selected_points: var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_first_index_pair_for_edge(se)) - + if eis.size() == 0: continue - + MDRMeshUtils.add_seam(_mdr, eis[0], eis[1]) - + _undo_redo.create_action("mark_seam") _undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(_mdr.seams)) _undo_redo.add_undo_method(self, "set_seam", _mdr, prev_seams) _undo_redo.commit_action() - + enable_change_event() elif selection_mode == SelectionMode.SELECTION_MODE_FACE: pass - -func unmark_seam(): + */ +} +void MDIGizmo::unmark_seam() { + /* if !_mdr: return - + if _selected_points.size() == 0: return - + if selection_mode == SelectionMode.SELECTION_MODE_VERTEX: pass elif selection_mode == SelectionMode.SELECTION_MODE_EDGE: disable_change_event() - + var prev_seams : PoolIntArray = copy_pool_int_array(_mdr.seams) - + for se in _selected_points: var eis : PoolIntArray = MDRMeshUtils.order_seam_indices(get_all_index_pairs_for_edge(se)) - + if eis.size() == 0: continue - + MDRMeshUtils.remove_seam(_mdr, eis[0], eis[1]) - + _undo_redo.create_action("unmark_seam") _undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(_mdr.seams)) _undo_redo.add_undo_method(self, "set_seam", _mdr, prev_seams) _undo_redo.commit_action() - + enable_change_event() elif selection_mode == SelectionMode.SELECTION_MODE_FACE: pass - -func set_seam(mdr : MeshDataResource, arr : PoolIntArray) -> void: + */ +} +void MDIGizmo::set_seam(Ref mdr, PoolIntArray arr) { + /* mdr.seams = arr - -func apply_seam(): + */ +} +void MDIGizmo::apply_seam() { + /* if !_mdr: return - + disable_change_event() - + var orig_arr : Array = copy_arrays(_mdr.array) MDRMeshUtils.apply_seam(_mdr) add_mesh_change_undo_redo(orig_arr, _mdr.array, "apply_seam") - - enable_change_event() -func clean_mesh(): + enable_change_event() + */ +} + +void MDIGizmo::clean_mesh() { + /* if !_mdr: return - + var arrays : Array = _mdr.array - + if arrays.size() != ArrayMesh.ARRAY_MAX: return arrays - + if arrays[ArrayMesh.ARRAY_VERTEX] == null || arrays[ArrayMesh.ARRAY_INDEX] == null: return arrays - + var old_vert_size : int = arrays[ArrayMesh.ARRAY_VERTEX].size() - + disable_change_event() - + var orig_arr : Array = copy_arrays(arrays) arrays = MDRMeshUtils.remove_used_vertices(arrays) var new_vert_size : int = arrays[ArrayMesh.ARRAY_VERTEX].size() add_mesh_change_undo_redo(orig_arr, arrays, "clean_mesh") - - enable_change_event() - - var d : int = old_vert_size - new_vert_size - - print("MDRED: Removed " + str(d) + " unused vertices.") -func uv_unwrap() -> void: + enable_change_event() + + var d : int = old_vert_size - new_vert_size + + print("MDRED: Removed " + str(d) + " unused vertices.") + */ +} + +void MDIGizmo::uv_unwrap() { + /* if !_mdr: return var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return - + disable_change_event() - + var uvs : PoolVector2Array = MeshUtils.uv_unwrap(mdr_arr) - + if uvs.size() != mdr_arr[ArrayMesh.ARRAY_VERTEX].size(): print("Error: Could not unwrap mesh!") enable_change_event(false) return - + var orig_arr : Array = copy_arrays(mdr_arr) - + mdr_arr[ArrayMesh.ARRAY_TEX_UV] = uvs - + add_mesh_change_undo_redo(orig_arr, mdr_arr, "uv_unwrap") enable_change_event() - -func flip_selected_faces() -> void: + */ +} +void MDIGizmo::flip_selected_faces() { + /* 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: +void MDIGizmo::add_mesh_change_undo_redo(Array orig_arr, Array new_arr, String action_name) { + /* _undo_redo.create_action(action_name) var nac : Array = copy_arrays(new_arr) _undo_redo.add_do_method(self, "apply_mesh_change", _mdr, nac) _undo_redo.add_undo_method(self, "apply_mesh_change", _mdr, orig_arr) _undo_redo.commit_action() - -func add_mesh_seam_change_undo_redo(orig_arr : Array, orig_seams : PoolIntArray, new_arr : Array, new_seams : PoolIntArray, action_name : String) -> void: + */ +} +void MDIGizmo::add_mesh_seam_change_undo_redo(Array orig_arr, PoolIntArray orig_seams, Array new_arr, PoolIntArray new_seams, String action_name) { + /* _undo_redo.create_action(action_name) var nac : Array = copy_arrays(new_arr) - + _undo_redo.add_do_method(self, "apply_mesh_change", _mdr, nac) _undo_redo.add_undo_method(self, "apply_mesh_change", _mdr, orig_arr) - + _undo_redo.add_do_method(self, "set_seam", _mdr, copy_pool_int_array(new_seams)) _undo_redo.add_undo_method(self, "set_seam", _mdr, orig_seams) - + _undo_redo.commit_action() + */ +} -func apply_mesh_change(mdr : MeshDataResource, arr : Array) -> void: +void MDIGizmo::apply_mesh_change(Ref mdr, Array arr) { + /* if !mdr: return - + mdr.array = copy_arrays(arr) - -func apply_vertex_array(mdr : MeshDataResource, verts : PoolVector3Array) -> void: + */ +} +void MDIGizmo::apply_vertex_array(Ref mdr, PoolVector3Array verts) { + /* if !mdr: return - + var mdr_arr : Array = mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX: return - + mdr_arr[ArrayMesh.ARRAY_VERTEX] = verts mdr.array = mdr_arr + */ +} -func copy_arrays(arr : Array) -> Array: +Array MDIGizmo::copy_arrays(Array arr) { + /* return arr.duplicate(true) - -func copy_pool_int_array(pia : PoolIntArray) -> PoolIntArray: + */ +} +PoolIntArray MDIGizmo::copy_pool_int_array(PoolIntArray pia) { + /* var ret : PoolIntArray = PoolIntArray() ret.resize(pia.size()) - + for i in range(pia.size()): ret[i] = pia[i] - - return ret -func copy_mdr_verts_array() -> PoolVector3Array: + return ret + */ +} +PoolVector3Array MDIGizmo::copy_mdr_verts_array() { + /* var ret : PoolVector3Array = PoolVector3Array() - + if !_mdr: return ret var mdr_arr : Array = _mdr.array - + if mdr_arr.size() != ArrayMesh.ARRAY_MAX || mdr_arr[ArrayMesh.ARRAY_VERTEX] == null || mdr_arr[ArrayMesh.ARRAY_VERTEX].size() == 0: return ret - + var vertices : PoolVector3Array = mdr_arr[ArrayMesh.ARRAY_VERTEX] ret.append_array(vertices) - - return ret -func setup_op_drag_indices() -> void: + return ret + */ +} + +void MDIGizmo::setup_op_drag_indices() { + /* _drag_op_indices.resize(0) - + for sp in _selected_points: var pi : PoolIntArray = _handle_to_vertex_map[sp] - + for indx in pi: if !pool_int_arr_contains(_drag_op_indices, indx): _drag_op_indices.append(indx) - -func get_drag_op_pivot() -> Vector3: + */ +} +Vector3 MDIGizmo::get_drag_op_pivot() { + /* if pivot_type == PivotTypes.PIVOT_TYPE_AVERAGED: var avg : Vector3 = Vector3() - + for indx in _drag_op_indices: avg += _vertices[indx] - + avg /= _drag_op_indices.size() return avg @@ -1759,12 +1877,15 @@ func get_drag_op_pivot() -> Vector3: return Vector3() elif pivot_type == PivotTypes.PIVOT_TYPE_WORLD_ORIGIN: return get_spatial_node().to_local(Vector3()) - - return Vector3() -func select_handle_points(points : PoolVector3Array) -> void: + return Vector3() + */ +} + +void MDIGizmo::select_handle_points(PoolVector3Array points) { + /* _selected_points.resize(0) - + for p in points: for i in range(_handle_points.size()): if is_verts_equal(p, _handle_points[i]): @@ -1772,45 +1893,102 @@ func select_handle_points(points : PoolVector3Array) -> void: _selected_points.push_back(i) redraw() + */ +} -func set_pivot_averaged(): +void MDIGizmo::set_pivot_averaged() { + /* pivot_type = PivotTypes.PIVOT_TYPE_AVERAGED - -func set_pivot_mdi_origin(): + */ +} +void MDIGizmo::set_pivot_mdi_origin() { + /* pivot_type = PivotTypes.PIVOT_TYPE_MDI_ORIGIN - -func set_pivot_world_origin(): + */ +} +void MDIGizmo::set_pivot_world_origin() { + /* pivot_type = PivotTypes.PIVOT_TYPE_WORLD_ORIGIN + */ +} -func transfer_state_from(other) -> void: +void MDIGizmo::transfer_state_from(EditorSpatialGizmo *other) { + /* edit_mode = other.edit_mode pivot_type = other.pivot_type axis_constraint = other.axis_constraint selection_mode = other.selection_mode handle_selection_type = other.handle_selection_type - + visual_indicator_outline = other.visual_indicator_outline visual_indicator_seam = other.visual_indicator_seam visual_indicator_handle = other.visual_indicator_handle + */ +} -func visual_indicator_outline_set(on : bool): +void MDIGizmo::visual_indicator_outline_set(bool on) { + /* visual_indicator_outline = on redraw() - -func visual_indicator_seam_set(on : bool): + */ +} +void MDIGizmo::visual_indicator_seam_set(bool on) { + /* visual_indicator_seam = on redraw() - -func visual_indicator_handle_set(on : bool): + */ +} +void MDIGizmo::visual_indicator_handle_set(bool on) { + /* visual_indicator_handle = on redraw() -func handle_selection_type_front(): - handle_selection_type = HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT - -func handle_selection_type_back(): - handle_selection_type = HandleSelectionType.HANDLE_SELECTION_TYPE_BACK - -func handle_selection_type_all(): - handle_selection_type = HandleSelectionType.HANDLE_SELECTION_TYPE_ALL + */ +} +void MDIGizmo::handle_selection_type_front() { + /* + handle_selection_type = HandleSelectionType.HANDLE_SELECTION_TYPE_FRONT + */ +} +void MDIGizmo::handle_selection_type_back() { + /* + handle_selection_type = HandleSelectionType.HANDLE_SELECTION_TYPE_BACK + */ +} +void MDIGizmo::handle_selection_type_all() { + /* + handle_selection_type = HandleSelectionType.HANDLE_SELECTION_TYPE_ALL + */ +} + +MDIGizmo::MDIGizmo() { + gizmo_size = 3.0; + + edit_mode = EDIT_MODE_TRANSLATE; + pivot_type = PIVOT_TYPE_AVERAGED; + axis_constraint = AXIS_CONSTRAINT_X | AXIS_CONSTRAINT_Y | AXIS_CONSTRAINT_Z; + selection_mode = SELECTION_MODE_VERTEX; + handle_selection_type = HANDLE_SELECTION_TYPE_FRONT; + visual_indicator_outline = true; + visual_indicator_seam = true; + visual_indicator_handle = true; + + _last_known_camera_facing = Vector3(0, 0, -1); + + _rect_drag = false; + _rect_drag_min_ofset = 10; + + _mesh_outline_generator.instance(); + + _handle_drag_op = false; + + _editor_plugin = nullptr; + _undo_redo = nullptr; +} + +MDIGizmo::~MDIGizmo() { +} + +void MDIGizmo::_bind_methods() { +} diff --git a/modules/mesh_data_resource/editor/mdi_gizmo.h b/modules/mesh_data_resource/editor/mdi_gizmo.h new file mode 100644 index 000000000..f81baa3fe --- /dev/null +++ b/modules/mesh_data_resource/editor/mdi_gizmo.h @@ -0,0 +1,243 @@ +#ifndef MDI_GIZMO_H +#define MDI_GIZMO_H + +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "editor/plugins/spatial_editor_plugin.h" + +#include "core/pool_vector.h" +#include "core/variant.h" +#include "core/math/vector3.h" +#include "core/reference.h" +#include "core/math/basis.h" +#include "core/math/transform.h" + +class Camera; +class MeshDataResource; +class MeshOutlineGenerator; +class InputEvent; +class EditorPlugin; +class UndoRedo; + +class MDIGizmo : public EditorSpatialGizmo { + GDCLASS(MDIGizmo, EditorSpatialGizmo); + +public: + enum EditMode { + EDIT_MODE_NONE = 0, + EDIT_MODE_TRANSLATE = 1, + EDIT_MODE_SCALE = 2, + EDIT_MODE_ROTATE = 3 + }; + + enum AxisConstraint { + AXIS_CONSTRAINT_X = 1 << 0, + AXIS_CONSTRAINT_Y = 1 << 1, + AXIS_CONSTRAINT_Z = 1 << 2, + }; + + enum SelectionMode { + SELECTION_MODE_VERTEX = 0, + SELECTION_MODE_EDGE = 1, + SELECTION_MODE_FACE = 2, + }; + + enum PivotTypes { + PIVOT_TYPE_AVERAGED = 0, + PIVOT_TYPE_MDI_ORIGIN = 1, + PIVOT_TYPE_WORLD_ORIGIN = 2, + }; + + enum HandleSelectionType { + HANDLE_SELECTION_TYPE_FRONT = 0, + HANDLE_SELECTION_TYPE_BACK = 1, + HANDLE_SELECTION_TYPE_ALL = 2, + }; + + void setup(); + void set_editor_plugin(EditorPlugin *editor_plugin); + + void set_handle(int index, Camera *camera, Vector2 point); + void redraw(); + void apply(); + + void select_all(); + + bool selection_click(int index, Camera *camera, const Ref &event); + bool is_point_visible(Vector3 point_orig, Vector3 camera_pos, Transform gt); + + void selection_click_select_front_or_back(int index, Camera *camera, const Ref &event); + void selection_click_select_through(int index, Camera *camera, const Ref &event); + void selection_drag(int index, Camera *camera, const Ref &event); + void selection_drag_rect_select_front_back(int index, Camera *camera, const Ref &event); + void selection_drag_rect_select_through(int index, Camera *camera, const Ref &event); + bool forward_spatial_gui_input(int index, Camera *camera, const Ref &event); + void add_to_all_selected(Vector3 ofs); + + void mul_all_selected_with_basis(Basis b); + void mul_all_selected_with_transform(Transform t); + void mul_all_selected_with_transform_acc(Transform t); + + void set_translate(); + void set_scale(); + void set_rotate(); + void set_edit_mode(int em); + + void set_axis_x(bool on); + void set_axis_y(bool on); + void set_axis_z(bool on); + + void set_selection_mode_vertex(); + void set_selection_mode_edge(); + void set_selection_mode_face(); + + void _notification(int what); + + void recalculate_handle_points(); + void on_mesh_data_resource_changed(Ref mdr); + void on_mdr_changed(); + void disable_change_event(); + void enable_change_event(bool update = true); + void add_triangle(); + void add_quad(); + + bool is_verts_equal(Vector3 v0, Vector3 v1); + Vector3 find_other_vertex_for_edge(int edge, Vector3 v0); + Array split_edge_indices(int edge); + bool pool_int_arr_contains(PoolIntArray arr, int val); + PoolIntArray find_triangles_for_edge(int edge); + int find_first_triangle_for_edge(int edge); + void add_triangle_to_edge(int edge); + void add_quad_to_edge(int edge); + void add_triangle_at(); + void add_quad_at(); + + void extrude(); + void add_box(); + void split(); + void disconnect_action(); + int get_first_triangle_index_for_vertex(int indx); + + void create_face(); + + Array split_face_indices(int face); + int find_first_triangle_index_for_face(int face); + + void delete_selected(); + void generate_normals(); + void generate_tangents(); + void remove_doubles(); + void merge_optimize(); + + void connect_to_first_selected(); + void connect_to_avg(); + void connect_to_last_selected(); + + PoolIntArray get_first_index_pair_for_edge(int edge); + PoolIntArray get_all_index_pairs_for_edge(int edge); + + void mark_seam(); + void unmark_seam(); + void set_seam(Ref mdr, PoolIntArray arr); + void apply_seam(); + + void clean_mesh(); + + void uv_unwrap(); + void flip_selected_faces(); + + void add_mesh_change_undo_redo(Array orig_arr, Array new_arr, String action_name); + void add_mesh_seam_change_undo_redo(Array orig_arr, PoolIntArray orig_seams, Array new_arr, PoolIntArray new_seams, String action_name); + + void apply_mesh_change(Ref mdr, Array arr); + void apply_vertex_array(Ref mdr, PoolVector3Array verts); + + Array copy_arrays(Array arr); + PoolIntArray copy_pool_int_array(PoolIntArray pia); + PoolVector3Array copy_mdr_verts_array(); + + void setup_op_drag_indices(); + Vector3 get_drag_op_pivot(); + + void select_handle_points(PoolVector3Array points); + + void set_pivot_averaged(); + void set_pivot_mdi_origin(); + void set_pivot_world_origin(); + + void transfer_state_from(EditorSpatialGizmo *other); + + void visual_indicator_outline_set(bool on); + void visual_indicator_seam_set(bool on); + void visual_indicator_handle_set(bool on); + + void handle_selection_type_front(); + void handle_selection_type_back(); + void handle_selection_type_all(); + + MDIGizmo(); + ~MDIGizmo(); + + float gizmo_size; + + int edit_mode; + int pivot_type; + int axis_constraint; + int selection_mode; + int handle_selection_type; + bool visual_indicator_outline; + bool visual_indicator_seam; + bool visual_indicator_handle; + + Vector2 previous_point; + Vector3 _last_known_camera_facing; + + bool _rect_drag; + Vector2 _rect_drag_start_point; + float _rect_drag_min_ofset; + + Ref _mdr; + + PoolVector3Array _vertices; + PoolIntArray _indices; + PoolVector3Array _handle_points; + Array _handle_to_vertex_map; + PoolIntArray _selected_points; + + Ref _mesh_outline_generator; + + bool _handle_drag_op; + PoolVector3Array _drag_op_orig_verices; + PoolIntArray _drag_op_indices; + Vector3 _drag_op_accumulator; + Quat _drag_op_accumulator_quat; + Vector3 _drag_op_pivot; + + EditorPlugin *_editor_plugin; + UndoRedo *_undo_redo; + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp b/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp new file mode 100644 index 000000000..c59510753 --- /dev/null +++ b/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp @@ -0,0 +1,63 @@ +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "mdi_gizmo_plugin.h" + +String MDIGizmoPlugin::get_name() const { + return "MDIGizmo"; +} +int MDIGizmoPlugin::get_priority() const { + return 100; +} +bool MDIGizmoPlugin::is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const { + return EditorSpatialGizmoPlugin::is_handle_highlighted(p_gizmo, p_idx); +} + +Ref MDIGizmoPlugin::create_gizmo(Spatial *p_spatial) { + /* + if spatial is MeshDataInstance: + var gizmo = MDIGizmo.new() + + gizmo.set_editor_plugin(plugin) + gizmo.set_spatial_node(spatial) + gizmo.setup() + plugin.register_gizmo(gizmo) + + return gizmo + else: + return null + */ +} + +MDIGizmoPlugin::MDIGizmoPlugin() { + plugin = nullptr; + + create_material("main", Color(0.7, 0.7, 0.7)); + create_material("seam", Color(1, 0, 0), false, true); + create_handle_material("handles"); +} + +MDIGizmoPlugin::~MDIGizmoPlugin() { +} + +void MDIGizmoPlugin::_bind_methods() { +} diff --git a/modules/mesh_data_resource/editor/mdi_gizmo_plugin.h b/modules/mesh_data_resource/editor/mdi_gizmo_plugin.h new file mode 100644 index 000000000..cd49e44d2 --- /dev/null +++ b/modules/mesh_data_resource/editor/mdi_gizmo_plugin.h @@ -0,0 +1,49 @@ +#ifndef MDI_GIZMO_PLUGIN_H +#define MDI_GIZMO_PLUGIN_H + +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "editor/plugins/spatial_editor_plugin.h" + +class MDIEdPlugin; + +class MDIGizmoPlugin : public EditorSpatialGizmoPlugin { + GDCLASS(MDIGizmoPlugin, EditorSpatialGizmoPlugin); + +public: + void _init(); + String get_name() const; + int get_priority() const; + bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const; + + MDIGizmoPlugin(); + ~MDIGizmoPlugin(); + + MDIEdPlugin *plugin; + +protected: + Ref create_gizmo(Spatial *p_spatial); + static void _bind_methods(); +}; + +#endif diff --git a/modules/mesh_data_resource/editor/addon/UVEditor.gd b/modules/mesh_data_resource/editor/uv_editor/mdi_ed_uv_editor.cpp similarity index 51% rename from modules/mesh_data_resource/editor/addon/UVEditor.gd rename to modules/mesh_data_resource/editor/uv_editor/mdi_ed_uv_editor.cpp index b04cef430..c78c9d756 100644 --- a/modules/mesh_data_resource/editor/addon/UVEditor.gd +++ b/modules/mesh_data_resource/editor/uv_editor/mdi_ed_uv_editor.cpp @@ -1,63 +1,102 @@ -tool -extends Control +/* +Copyright (c) 2019-2022 Péter Magyar -var mesh_data_resource : MeshDataResource = null setget set_mesh_data_resource -var background_texture : Texture = null +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -func set_mesh_data_resource(a : MeshDataResource): +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "mdi_ed_uv_editor.h" + +void MDIEdUVEditor::set_mesh_data_resource(Ref a) { + /* if mesh_data_resource: mesh_data_resource.disconnect("changed", self, "on_mdr_changed") - + mesh_data_resource = a - + if mesh_data_resource: mesh_data_resource.connect("changed", self, "on_mdr_changed") update() - -func set_mesh_data_instance(a : MeshDataInstance): + */ +} +void MDIEdUVEditor::set_mesh_data_instance(MeshDataInstance *a) { + /* + if !a: background_texture = null - + background_texture = a.texture -func on_mdr_changed(): - update() + */ +} +void MDIEdUVEditor::on_mdr_changed() { + update(); +} +void MDIEdUVEditor::_draw() { + /* -func _draw(): if background_texture: draw_texture_rect_region(background_texture, Rect2(Vector2(), get_size()), Rect2(Vector2(), background_texture.get_size())) - + if !mesh_data_resource: return - + if mesh_data_resource.array.size() != ArrayMesh.ARRAY_MAX: return - + var uvs : PoolVector2Array = mesh_data_resource.array[ArrayMesh.ARRAY_TEX_UV] var indices : PoolIntArray = mesh_data_resource.array[ArrayMesh.ARRAY_INDEX] - + if indices.size() % 3 == 0: for i in range(0, len(indices), 3): var c : Color = Color(1, 1, 1, 1) - + if uvs[indices[i]].is_equal_approx(Vector2()) || uvs[indices[i + 1]].is_equal_approx(Vector2()): c = Color(1, 0, 0, 1) else: c = Color(1, 1, 1, 1) - + draw_line(uvs[indices[i]] * get_size(), uvs[indices[i + 1]] * get_size(), c, 1, false) if uvs[indices[i + 1]].is_equal_approx(Vector2()) || uvs[indices[i + 2]].is_equal_approx(Vector2()): c = Color(1, 0, 0, 1) else: c = Color(1, 1, 1, 1) - + draw_line(uvs[indices[i + 1]] * get_size(), uvs[indices[i + 2]] * get_size(), c, 1, false) - + if uvs[indices[i + 2]].is_equal_approx(Vector2()) || uvs[indices[i]].is_equal_approx(Vector2()): c = Color(1, 0, 0, 1) else: c = Color(1, 1, 1, 1) draw_line(uvs[indices[i + 2]] * get_size(), uvs[indices[i]] * get_size(), c, 1, false) + + + */ +} + +MDIEdUVEditor::MDIEdUVEditor() { +} + +MDIEdUVEditor::~MDIEdUVEditor() { +} + +void MDIEdUVEditor::_bind_methods() { +} diff --git a/modules/mesh_data_resource/editor/uv_editor/mdi_ed_uv_editor.h b/modules/mesh_data_resource/editor/uv_editor/mdi_ed_uv_editor.h new file mode 100644 index 000000000..cbd64b358 --- /dev/null +++ b/modules/mesh_data_resource/editor/uv_editor/mdi_ed_uv_editor.h @@ -0,0 +1,53 @@ +#ifndef MDI_ED_UV_EDITOR_H +#define MDI_ED_UV_EDITOR_H + +/* +Copyright (c) 2019-2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/control.h" + +#include "core/reference.h" + +class MeshDataResource; +class MeshDataInstance; +class Texture; + +class MDIEdUVEditor : public Control { + GDCLASS(MDIEdUVEditor, Control); + +public: + void set_mesh_data_resource(Ref a); + void set_mesh_data_instance(MeshDataInstance *a); + void on_mdr_changed(); + void _draw(); + + MDIEdUVEditor(); + ~MDIEdUVEditor(); + +protected: + static void _bind_methods(); + + Ref mesh_data_resource; + Ref background_texture; +}; + +#endif