From befd0071b6e8c38b3f32ac22ad685582735ee322 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 25 Feb 2022 14:04:51 +0100 Subject: [PATCH] Updated the 2d PropDataEntry. Also registered it to the Prop2D singleton. --- props_2d/prop_2d_data_mesh_data.cpp | 29 ++++++++++++++++++----------- props_2d/prop_2d_data_mesh_data.h | 4 ++-- register_types.cpp | 11 +++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/props_2d/prop_2d_data_mesh_data.cpp b/props_2d/prop_2d_data_mesh_data.cpp index 698b87c..997df95 100644 --- a/props_2d/prop_2d_data_mesh_data.cpp +++ b/props_2d/prop_2d_data_mesh_data.cpp @@ -69,31 +69,38 @@ bool Prop2DDataMeshData::_processor_handles(Node *node) { return i; } -void Prop2DDataMeshData::_processor_process(Ref prop_data, Node *node, const Transform2D &transform) { +void Prop2DDataMeshData::_processor_process(Ref prop_data, Node *node, const Transform2D &transform, Ref entry) { MeshDataInstance *i = Object::cast_to(node); ERR_FAIL_COND(!i); Ref m; - m.instance(); + + if (entry.is_valid()) { + m = entry; + } else { + m.instance(); + } + m->set_mesh(i->get_mesh_data()); m->set_texture(i->get_texture()); - //m->set_transform(transform * i->get_transform()); - prop_data->add_prop(m); + + Prop2DDataEntry::_processor_process(prop_data, node, transform, m); } -Node *Prop2DDataMeshData::_processor_get_node_for(const Transform2D &transform) { - MeshDataInstance *i = memnew(MeshDataInstance); +Node *Prop2DDataMeshData::_processor_get_node_for(const Transform2D &transform, Node *node) { + MeshDataInstance *i = nullptr; - Ref m; - m.instance(); + if (!node) { + i = memnew(MeshDataInstance); + } else { + i = Object::cast_to(node); + } - i->set_material(m); i->set_texture(get_texture()); i->set_mesh_data(get_mesh()); - //i->set_transform(get_transform()); - return i; + return Prop2DDataEntry::_processor_get_node_for(transform, i); } Prop2DDataMeshData::Prop2DDataMeshData() { diff --git a/props_2d/prop_2d_data_mesh_data.h b/props_2d/prop_2d_data_mesh_data.h index 1846ac9..82217f5 100644 --- a/props_2d/prop_2d_data_mesh_data.h +++ b/props_2d/prop_2d_data_mesh_data.h @@ -59,8 +59,8 @@ public: #endif bool _processor_handles(Node *node); - void _processor_process(Ref prop_data, Node *node, const Transform2D &transform); - Node *_processor_get_node_for(const Transform2D &transform); + void _processor_process(Ref prop_data, Node *node, const Transform2D &transform, Ref entry = Ref()); + Node *_processor_get_node_for(const Transform2D &transform, Node *node = nullptr); Prop2DDataMeshData(); ~Prop2DDataMeshData(); diff --git a/register_types.cpp b/register_types.cpp index 927c500..880ba98 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -39,6 +39,11 @@ SOFTWARE. #include "props/prop_data_mesh_data.h" #endif +#if PROPS_2D_PRESENT +#include "../props_2d/singleton/prop_2d_utils.h" +#include "props_2d/prop_2d_data_mesh_data.h" +#endif + void register_mesh_data_resource_types() { ClassDB::register_class(); ClassDB::register_class(); @@ -51,6 +56,12 @@ void register_mesh_data_resource_types() { PropUtils::add_processor(processor); #endif +#if PROPS_2D_PRESENT + ClassDB::register_class(); + Ref prop_2d_processor = Ref(memnew(Prop2DDataMeshData)); + Prop2DUtils::add_processor(prop_2d_processor); +#endif + #ifdef TOOLS_ENABLED EditorPlugins::add_by_type();