mirror of
https://github.com/Relintai/props.git
synced 2024-11-12 10:15:25 +01:00
Added get_node_for to PropDataProcessor's api. Also work on PropInstance.
This commit is contained in:
parent
4a10f1d0fa
commit
b34a8f3996
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -30,12 +30,18 @@ bool PropDataProcessor::handles(Node *node) {
|
||||
void PropDataProcessor::process(Ref<PropData> prop_data, Node *node, const Transform &transform) {
|
||||
call("_process", prop_data, node, transform);
|
||||
}
|
||||
Node *PropDataProcessor::get_node_for(const Ref<PropData> &prop_data) {
|
||||
return call("_get_node_for", prop_data);
|
||||
}
|
||||
|
||||
bool PropDataProcessor::_handles(Node *node) {
|
||||
return false;
|
||||
}
|
||||
void PropDataProcessor::_process(Ref<PropData> prop_data, Node *node, const Transform &transform) {
|
||||
}
|
||||
Node *PropDataProcessor::_get_node_for(const Ref<PropData> &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);
|
||||
}
|
||||
|
@ -37,9 +37,11 @@ class PropDataProcessor : public Reference {
|
||||
public:
|
||||
bool handles(Node *node);
|
||||
void process(Ref<PropData> prop_data, Node *node, const Transform &transform);
|
||||
Node *get_node_for(const Ref<PropData> &prop_data);
|
||||
|
||||
virtual bool _handles(Node *node);
|
||||
virtual void _process(Ref<PropData> prop_data, Node *node, const Transform &transform);
|
||||
virtual Node *_get_node_for(const Ref<PropData> &prop_data);
|
||||
|
||||
PropDataProcessor();
|
||||
~PropDataProcessor();
|
||||
|
@ -4,6 +4,18 @@
|
||||
|
||||
#include "../thread_pool/thread_pool.h"
|
||||
|
||||
Ref<PropData> PropInstance::get_prop_data() {
|
||||
return _prop_data;
|
||||
}
|
||||
void PropInstance::set_prop_data(const Ref<PropData> &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<PropDataEntry> 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() {
|
||||
|
@ -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<PropData> get_prop_data();
|
||||
void set_prop_data(const Ref<PropData> &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<PropData> _prop_data;
|
||||
bool _auto_bake;
|
||||
bool _bake_queued;
|
||||
bool _baking;
|
||||
|
Loading…
Reference in New Issue
Block a user