diff --git a/modules/mesh_data_resource/editor/mdi_ed_plugin.cpp b/modules/mesh_data_resource/editor/mdi_ed_plugin.cpp index 56e284057..464a5c382 100644 --- a/modules/mesh_data_resource/editor/mdi_ed_plugin.cpp +++ b/modules/mesh_data_resource/editor/mdi_ed_plugin.cpp @@ -27,32 +27,7 @@ SOFTWARE. #include "mdi_gizmo.h" #include "mdi_gizmo_plugin.h" -void MDIEdPlugin::_enter_tree() { - gizmo_plugin = memnew(MDIGizmoPlugin); - mdi_ed_gui = memnew(MDIEd); - mdi_ed_gui->set_plugin(this); - active_gizmos.clear(); - - gizmo_plugin->plugin = this; - - 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(); -} -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_delete(); -} - bool MDIEdPlugin::handles(Object *object) const { - //print("disable_plugin") - if (object->is_class("MeshDataInstance")) { return true; } @@ -82,29 +57,15 @@ void MDIEdPlugin::make_visible(bool 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 + //else + //mdi_ed_gui.hide() + //figure out how to hide it when something else gets selected, don't hide on unselect } String MDIEdPlugin::get_name() const { return "MeshDataResourceEditor"; } -void MDIEdPlugin::register_gizmo(Ref gizmo) { - active_gizmos.push_back(gizmo); -} -void MDIEdPlugin::unregister_gizmo(Ref gizmo) { - for (int i = 0; i < active_gizmos.size(); ++i) { - if (active_gizmos[i] == gizmo) { - active_gizmos.remove(i); - return; - } - } -} - void MDIEdPlugin::set_translate() { if (current_mesh_data_instance) { Ref g = current_mesh_data_instance->get_gizmo(); @@ -398,23 +359,19 @@ void MDIEdPlugin::flip_selected_faces() { } } -MDIEdPlugin::MDIEdPlugin() { +MDIEdPlugin::MDIEdPlugin(EditorNode *p_node) { + editor = p_node; + current_mesh_data_instance = nullptr; - /* - const MDRMeshUtils = preload("res://addons/mesh_data_resource_editor/utilities/mdred_mesh_utils.gd") + mdi_ed_gui = memnew(MDIEd); + mdi_ed_gui->set_plugin(this); + add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, mdi_ed_gui); + mdi_ed_gui->hide(); - 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 - - */ + gizmo_plugin.instance(); + gizmo_plugin->plugin = this; + add_spatial_gizmo_plugin(gizmo_plugin); } MDIEdPlugin::~MDIEdPlugin() { diff --git a/modules/mesh_data_resource/editor/mdi_ed_plugin.h b/modules/mesh_data_resource/editor/mdi_ed_plugin.h index 4d79c1aab..ae7ebdc9f 100644 --- a/modules/mesh_data_resource/editor/mdi_ed_plugin.h +++ b/modules/mesh_data_resource/editor/mdi_ed_plugin.h @@ -38,19 +38,15 @@ class MeshDataInstance; class MDIEd; class MDIEdPlugin : public EditorPlugin { -public: - void _enter_tree(); - void _exit_tree(); + GDCLASS(MDIEdPlugin, EditorPlugin); +public: bool handles(Object *object) const; void edit(Object *object); void make_visible(bool visible); String get_name() const; - void register_gizmo(Ref gizmo); - void unregister_gizmo(Ref gizmo); - void set_translate(); void set_scale(); void set_rotate(); @@ -115,16 +111,16 @@ public: void flip_selected_faces(); - MDIEdPlugin(); + MDIEdPlugin(EditorNode *p_node); ~MDIEdPlugin(); - MDIGizmoPlugin *gizmo_plugin; + Ref gizmo_plugin; MDIEd *mdi_ed_gui; - Vector> active_gizmos; - MeshDataInstance *current_mesh_data_instance; + EditorNode *editor; + protected: static void _bind_methods(); }; diff --git a/modules/mesh_data_resource/editor/mdi_gizmo.cpp b/modules/mesh_data_resource/editor/mdi_gizmo.cpp index 22765366c..ab5ffa7f4 100644 --- a/modules/mesh_data_resource/editor/mdi_gizmo.cpp +++ b/modules/mesh_data_resource/editor/mdi_gizmo.cpp @@ -770,15 +770,6 @@ void MDIGizmo::set_selection_mode_face() { redraw(); } -void MDIGizmo::_notification(int what) { - /* - if (what == NOTIFICATION_PREDELETE) { - if (this != nullptr && get_plugin().is_valid()) { - get_plugin()->unregister_gizmo(this); - } - }*/ -} - void MDIGizmo::recalculate_handle_points() { if (!_mdr.is_valid()) { _handle_points.resize(0); diff --git a/modules/mesh_data_resource/editor/mdi_gizmo.h b/modules/mesh_data_resource/editor/mdi_gizmo.h index a0536f4b8..5b0072666 100644 --- a/modules/mesh_data_resource/editor/mdi_gizmo.h +++ b/modules/mesh_data_resource/editor/mdi_gizmo.h @@ -110,9 +110,7 @@ public: 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(); diff --git a/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp b/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp index fa92b4c96..e6204c763 100644 --- a/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp +++ b/modules/mesh_data_resource/editor/mdi_gizmo_plugin.cpp @@ -46,7 +46,6 @@ Ref MDIGizmoPlugin::create_gizmo(Spatial *p_spatial) { gizmo->set_editor_plugin(plugin); gizmo->set_spatial_node(p_spatial); gizmo->setup(); - plugin->register_gizmo(gizmo); return gizmo; } else { diff --git a/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.cpp b/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.cpp index e049dc156..4b83030cf 100644 --- a/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.cpp +++ b/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.cpp @@ -89,7 +89,7 @@ void MDREDMeshOutline::generate(bool mark_outline, bool mark_handles) { if (mark_outline) { for (int i = 0; i < _indices.size(); i += 3) { - for (int j = 0; j < 4; ++j) { + for (int j = 0; j < 3; ++j) { lines.push_back(get_vertex(_indices[i + j])); lines.push_back(get_vertex(_indices[i + ((j + 1) % 3)])); } @@ -211,5 +211,8 @@ MDREDMeshOutline::MDREDMeshOutline() { marker_size = 0.05; } +MDREDMeshOutline::~MDREDMeshOutline() { +} + void MDREDMeshOutline::_bind_methods() { } \ No newline at end of file diff --git a/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.h b/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.h index d9e226ac6..944985976 100644 --- a/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.h +++ b/modules/mesh_data_resource/editor/utilities/mdr_ed_mesh_outline.h @@ -44,6 +44,7 @@ public: void generate_mark_faces(bool mark_outline, bool mark_handles); MDREDMeshOutline(); + ~MDREDMeshOutline(); float marker_size; diff --git a/modules/mesh_data_resource/register_types.cpp b/modules/mesh_data_resource/register_types.cpp index 38c0a144a..60c2bcb85 100644 --- a/modules/mesh_data_resource/register_types.cpp +++ b/modules/mesh_data_resource/register_types.cpp @@ -31,6 +31,8 @@ SOFTWARE. #include "editor/editor_plugin.h" #include "plugin_gltf/editor_plugin_gltf_mdr.h" + +#include "./editor/mdi_ed_plugin.h" #endif #if PROPS_PRESENT @@ -64,6 +66,7 @@ void register_mesh_data_resource_types() { #ifdef TOOLS_ENABLED EditorPlugins::add_by_type(); + EditorPlugins::add_by_type(); #endif }