diff --git a/editor/prop_editor_plugin.cpp b/editor/prop_editor_plugin.cpp index fcf4726..ff95a23 100644 --- a/editor/prop_editor_plugin.cpp +++ b/editor/prop_editor_plugin.cpp @@ -24,8 +24,10 @@ SOFTWARE. #include "../props/prop_data.h" #include "../singleton/prop_utils.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" -void PropEditorPlugin::convert_active_scene_to_prop_data(Variant param) { +void PropEditorPlugin::convert_active_scene_to_prop_data() { SceneTree *st = SceneTree::get_singleton(); if (st) { @@ -39,7 +41,7 @@ void PropEditorPlugin::convert_active_scene_to_prop_data(Variant param) { } } } -void PropEditorPlugin::convert_selected_scene_to_prop_data(Variant param) { +void PropEditorPlugin::convert_selected_scene_to_prop_data() { } void PropEditorPlugin::convert_scene(Node *root, const String &path) { @@ -60,12 +62,37 @@ void PropEditorPlugin::convert_scene(Node *root, const String &path) { s.save(path, data); } +void PropEditorPlugin::_quick_convert_button_pressed() { + convert_active_scene_to_prop_data(); +} + +void PropEditorPlugin::_convert_active_scene_to_prop_data(Variant param) { + convert_active_scene_to_prop_data(); +} +void PropEditorPlugin::_convert_selected_scene_to_prop_data(Variant param) { + convert_selected_scene_to_prop_data(); +} + PropEditorPlugin::PropEditorPlugin(EditorNode *p_node) { editor = p_node; editor->add_tool_menu_item("Convert active scene to PropData", this, "convert_active_scene_to_prop_data"); editor->add_tool_menu_item("Convert selected scene(s) to PropData", this, "convert_selected_scene_to_prop_data"); + + HBoxContainer *container = memnew(HBoxContainer); + + container->add_child(memnew(VSeparator)); + + Button *b = memnew(Button); + container->add_child(b); + b->set_flat(true); + + b->connect("pressed", this, "_quick_convert_button_pressed"); + b->set_text("To Prop"); + b->set_shortcut(ED_SHORTCUT("spatial_editor/quick_prop_convert", "Quick convert scene to PropData.", KEY_MASK_ALT + KEY_U)); + + add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, container); } PropEditorPlugin::~PropEditorPlugin() { @@ -74,4 +101,6 @@ PropEditorPlugin::~PropEditorPlugin() { void PropEditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("convert_active_scene_to_prop_data"), &PropEditorPlugin::convert_active_scene_to_prop_data); ClassDB::bind_method(D_METHOD("convert_selected_scene_to_prop_data"), &PropEditorPlugin::convert_selected_scene_to_prop_data); + + ClassDB::bind_method(D_METHOD("_quick_convert_button_pressed"), &PropEditorPlugin::_quick_convert_button_pressed); } diff --git a/editor/prop_editor_plugin.h b/editor/prop_editor_plugin.h index 62b0cd2..47e18a1 100644 --- a/editor/prop_editor_plugin.h +++ b/editor/prop_editor_plugin.h @@ -43,10 +43,14 @@ public: virtual bool handles(Object *p_object) const { return false; } virtual void make_visible(bool p_visible) {} - void convert_active_scene_to_prop_data(Variant param); - void convert_selected_scene_to_prop_data(Variant param); + void convert_active_scene_to_prop_data(); + void convert_selected_scene_to_prop_data(); void convert_scene(Node *root, const String &path); + void _convert_active_scene_to_prop_data(Variant param); + void _convert_selected_scene_to_prop_data(Variant param); + void _quick_convert_button_pressed(); + PropEditorPlugin(EditorNode *p_node); ~PropEditorPlugin(); }; diff --git a/processor/prop_data_processor.cpp b/processor/prop_data_processor.cpp index 903fa7e..a2d0ae6 100644 --- a/processor/prop_data_processor.cpp +++ b/processor/prop_data_processor.cpp @@ -30,12 +30,18 @@ bool PropDataProcessor::handles(Node *node) { void PropDataProcessor::process(Ref prop_data, Node *node, const Transform &transform) { call("_process", prop_data, node, transform); } +Node *PropDataProcessor::get_node_for(const Ref &prop_data) { + return call("_get_node_for", prop_data); +} bool PropDataProcessor::_handles(Node *node) { return false; } void PropDataProcessor::_process(Ref prop_data, Node *node, const Transform &transform) { } +Node *PropDataProcessor::_get_node_for(const Ref &prop_data) { + return NULL; +} PropDataProcessor::PropDataProcessor() { } @@ -49,9 +55,14 @@ void PropDataProcessor::_bind_methods() { PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::TRANSFORM, "transform"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"), "_get_node_for", + PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"))); + ClassDB::bind_method(D_METHOD("handles", "node"), &PropDataProcessor::handles); ClassDB::bind_method(D_METHOD("process", "prop_data", "node", "transform"), &PropDataProcessor::process); + ClassDB::bind_method(D_METHOD("get_node_for", "prop_data"), &PropDataProcessor::get_node_for); ClassDB::bind_method(D_METHOD("_handles", "node"), &PropDataProcessor::_handles); ClassDB::bind_method(D_METHOD("_process", "prop_data", "node", "transform"), &PropDataProcessor::_process); + ClassDB::bind_method(D_METHOD("_get_node_for", "prop_data"), &PropDataProcessor::_get_node_for); } diff --git a/processor/prop_data_processor.h b/processor/prop_data_processor.h index 4006f99..c675cc5 100644 --- a/processor/prop_data_processor.h +++ b/processor/prop_data_processor.h @@ -37,9 +37,11 @@ class PropDataProcessor : public Reference { public: bool handles(Node *node); void process(Ref prop_data, Node *node, const Transform &transform); + Node *get_node_for(const Ref &prop_data); virtual bool _handles(Node *node); virtual void _process(Ref prop_data, Node *node, const Transform &transform); + virtual Node *_get_node_for(const Ref &prop_data); PropDataProcessor(); ~PropDataProcessor(); diff --git a/prop_instance.cpp b/prop_instance.cpp index 8a4ff9e..11ce20d 100644 --- a/prop_instance.cpp +++ b/prop_instance.cpp @@ -4,6 +4,18 @@ #include "../thread_pool/thread_pool.h" +Ref PropInstance::get_prop_data() { + return _prop_data; +} +void PropInstance::set_prop_data(const Ref &data) { + if (_prop_data == data) + return; + + _prop_data = data; + + build(); +} + bool PropInstance::get_auto_bake() const { return _auto_bake; } @@ -95,6 +107,26 @@ void PropInstance::queue_bake() { } } +void PropInstance::build() { + if (!is_inside_tree()) { + return; + } + + for (int i = 0; i < get_child_count(); ++i) { + get_child(i)->queue_delete(); + } + + if (!_prop_data.is_valid()) + return; + + for (int i = 0; i < _prop_data->get_prop_count(); ++i) { + Ref e = _prop_data->get_prop(i); + + if (!e.is_valid()) + continue; + } +} + PropInstance::PropInstance() { _baking = false; _bake_queued = false; @@ -106,6 +138,7 @@ PropInstance::PropInstance() { PropInstance::~PropInstance() { _mesh_data_instances.clear(); _job.unref(); + _prop_data.unref(); } void PropInstance::_bind_methods() { diff --git a/prop_instance.h b/prop_instance.h index 5d67170..a769bef 100644 --- a/prop_instance.h +++ b/prop_instance.h @@ -37,13 +37,17 @@ SOFTWARE. #include "prop_instance_job.h" +#include "props/prop_data.h" + class MeshDataInstance; class PropInstance : public Spatial { GDCLASS(PropInstance, Spatial); - OBJ_CATEGORY("Props"); public: + Ref get_prop_data(); + void set_prop_data(const Ref &data); + bool get_auto_bake() const; void set_auto_bake(const bool value); @@ -60,6 +64,8 @@ public: void queue_bake(); void bake_finished(); + void build(); + PropInstance(); ~PropInstance(); @@ -67,6 +73,7 @@ protected: static void _bind_methods(); private: + Ref _prop_data; bool _auto_bake; bool _bake_queued; bool _baking;