Small cleanups, and enabled / registered the mesh data instance editor plugins. Editing itself seems to work, however the UI still need to be fixed.

This commit is contained in:
Relintai 2022-04-13 19:39:31 +02:00
parent cd3366f6c4
commit 496b1b7f34
8 changed files with 28 additions and 80 deletions

View File

@ -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<MDIGizmo> gizmo) {
active_gizmos.push_back(gizmo);
}
void MDIEdPlugin::unregister_gizmo(Ref<MDIGizmo> 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<MDIGizmo> 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() {

View File

@ -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<MDIGizmo> gizmo);
void unregister_gizmo(Ref<MDIGizmo> 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<MDIGizmoPlugin> gizmo_plugin;
MDIEd *mdi_ed_gui;
Vector<Ref<MDIGizmo>> active_gizmos;
MeshDataInstance *current_mesh_data_instance;
EditorNode *editor;
protected:
static void _bind_methods();
};

View File

@ -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);

View File

@ -111,8 +111,6 @@ public:
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<MeshDataResource> mdr);
void on_mdr_changed();

View File

@ -46,7 +46,6 @@ Ref<EditorSpatialGizmo> 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 {

View File

@ -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() {
}

View File

@ -44,6 +44,7 @@ public:
void generate_mark_faces(bool mark_outline, bool mark_handles);
MDREDMeshOutline();
~MDREDMeshOutline();
float marker_size;

View File

@ -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<EditorPluginGLTFMdr>();
EditorPlugins::add_by_type<MDIEdPlugin>();
#endif
}