From c3ac4bf02a4dc6b110538667ba2d80107e8e522e Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 16 Jun 2020 15:53:33 +0200 Subject: [PATCH] Added a type property to ModelVisualEntry, also it now hides the irrelevant properties based on it's type. Implemented handling of the attachment ModelVisuals in CharacterSkeleton3D. Also Small api change to CharacterSkeleton3D. --- data/items/model_visual_entry.cpp | 57 +++++++++++++++++++++++------- data/items/model_visual_entry.h | 14 ++++++++ skeleton/character_skeleton_3d.cpp | 52 ++++++++++++++++++++------- skeleton/character_skeleton_3d.h | 6 ++-- 4 files changed, 101 insertions(+), 28 deletions(-) diff --git a/data/items/model_visual_entry.cpp b/data/items/model_visual_entry.cpp index 0c45c2d..3cc157e 100644 --- a/data/items/model_visual_entry.cpp +++ b/data/items/model_visual_entry.cpp @@ -24,6 +24,15 @@ SOFTWARE. #include "../../singletons/ess.h" +const String ModelVisualEntry::BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES = "Bone,Attachment"; + +ModelVisualEntry::ModenVisualEntryType ModelVisualEntry::get_type() const { + return _type; +} +void ModelVisualEntry::set_type(const ModelVisualEntry::ModenVisualEntryType type) { + _type = type; +} + int ModelVisualEntry::get_override_layer() const { return _override_layer; } @@ -116,6 +125,7 @@ void ModelVisualEntry::set_size(const int value) { } ModelVisualEntry::ModelVisualEntry() { + _type = MODEL_VISUAL_ENTRY_TYPE_BONE; _override_layer = 0; _entity_type = 0; @@ -209,35 +219,53 @@ bool ModelVisualEntry::_get(const StringName &p_name, Variant &r_ret) const { } void ModelVisualEntry::_get_property_list(List *p_list) const { for (int i = 0; i < _entries.size(); ++i) { + if (_type == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_BONE) { #ifdef MESH_DATA_RESOURCE_PRESENT - p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/mesh", PROPERTY_HINT_RESOURCE_TYPE, "MeshDataResource", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL)); #endif - p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture")); - p_list->push_back(PropertyInfo(Variant::COLOR, "entry_" + itos(i) + "/color")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/attachment", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene")); - p_list->push_back(PropertyInfo(Variant::TRANSFORM, "entry_" + itos(i) + "/transform")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL)); + p_list->push_back(PropertyInfo(Variant::COLOR, "entry_" + itos(i) + "/color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL)); + } else { + p_list->push_back(PropertyInfo(Variant::OBJECT, "entry_" + itos(i) + "/attachment", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL)); + } + p_list->push_back(PropertyInfo(Variant::TRANSFORM, "entry_" + itos(i) + "/transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL)); } } void ModelVisualEntry::_validate_property(PropertyInfo &property) const { String name = property.name; + if (_type == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_BONE) { + if (name == "entity_type") { + property.usage = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED; + property.hint_string = ESS::get_singleton()->entity_types_get(); + } else if (name == "bone") { + if (ESS::get_singleton()->skeletons_bones_count() > _entity_type) { + property.hint_string = ESS::get_singleton()->skeletons_bones_index_get(_entity_type); + } else { + property.hint_string = ""; + } + } + } else { + if (name == "entity_type") { + property.usage = PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED; + } else if (name == "bone") { + property.hint_string = EntityEnums::BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS; + } + } + if (name == "group") { property.hint_string = ESS::get_singleton()->model_visual_groups_get(); - } else if (name == "bone") { - if (ESS::get_singleton()->skeletons_bones_count() > _entity_type) { - property.hint_string = ESS::get_singleton()->skeletons_bones_index_get(_entity_type); - } else { - property.hint_string = ""; - } - } else if (name == "entity_type") { - property.hint_string = ESS::get_singleton()->entity_types_get(); } else if (name == "override_layer") { property.hint_string = ESS::get_singleton()->texture_layers_get(); } } void ModelVisualEntry::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_type"), &ModelVisualEntry::get_type); + ClassDB::bind_method(D_METHOD("set_type", "value"), &ModelVisualEntry::set_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, ModelVisualEntry::BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_type", "get_type"); + ClassDB::bind_method(D_METHOD("get_override_layer"), &ModelVisualEntry::get_override_layer); ClassDB::bind_method(D_METHOD("set_override_layer", "value"), &ModelVisualEntry::set_override_layer); ADD_PROPERTY(PropertyInfo(Variant::INT, "override_layer", PROPERTY_HINT_ENUM, ""), "set_override_layer", "get_override_layer"); @@ -274,4 +302,7 @@ void ModelVisualEntry::_bind_methods() { ClassDB::bind_method(D_METHOD("get_size"), &ModelVisualEntry::get_size); ClassDB::bind_method(D_METHOD("set_size", "value"), &ModelVisualEntry::set_size); ADD_PROPERTY(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_size", "get_size"); + + BIND_ENUM_CONSTANT(MODEL_VISUAL_ENTRY_TYPE_BONE); + BIND_ENUM_CONSTANT(MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT); } diff --git a/data/items/model_visual_entry.h b/data/items/model_visual_entry.h index bcb3ef8..ce817b0 100644 --- a/data/items/model_visual_entry.h +++ b/data/items/model_visual_entry.h @@ -42,6 +42,17 @@ class ModelVisualEntry : public Resource { GDCLASS(ModelVisualEntry, Resource); public: + enum ModenVisualEntryType { + MODEL_VISUAL_ENTRY_TYPE_BONE = 0, + MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT + }; + + static const String BINDING_STRING_MODEL_VISUAL_ENTRY_TYPES; + +public: + ModelVisualEntry::ModenVisualEntryType get_type() const; + void set_type(const ModelVisualEntry::ModenVisualEntryType type); + int get_override_layer() const; void set_override_layer(const int layer); @@ -109,6 +120,7 @@ protected: static void _bind_methods(); private: + ModelVisualEntry::ModenVisualEntryType _type; int _override_layer; int _entity_type; @@ -118,4 +130,6 @@ private: Vector _entries; }; +VARIANT_ENUM_CAST(ModelVisualEntry::ModenVisualEntryType); + #endif diff --git a/skeleton/character_skeleton_3d.cpp b/skeleton/character_skeleton_3d.cpp index 593c9d8..061a94c 100644 --- a/skeleton/character_skeleton_3d.cpp +++ b/skeleton/character_skeleton_3d.cpp @@ -81,37 +81,37 @@ Node *CharacterSkeleton3D::common_attach_point_node_get(const EntityEnums::Commo return _attach_point_nodes[common_attach_point_index_get(index)].node; } -void CharacterSkeleton3D::common_attach_point_add_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene) { +void CharacterSkeleton3D::common_attach_point_add(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene) { int index = common_attach_point_index_get(point); ERR_FAIL_INDEX(index, _attach_point_nodes.size()); Node *n = _attach_point_nodes[index].node; - if (INSTANCE_VALIDATE(n) && n->has_method("add_effect")) { - n->call("add_effect", scene); + if (INSTANCE_VALIDATE(n) && n->has_method("add")) { + n->call("add", scene); } } -void CharacterSkeleton3D::common_attach_point_add_effect_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene, const float time) { +void CharacterSkeleton3D::common_attach_point_add_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene, const float time) { int index = common_attach_point_index_get(point); ERR_FAIL_INDEX(index, _attach_point_nodes.size()); Node *n = _attach_point_nodes[index].node; - if (INSTANCE_VALIDATE(n) && n->has_method("add_effect_timed")) { - n->call("add_effect_timed", scene, time); + if (INSTANCE_VALIDATE(n) && n->has_method("add_timed")) { + n->call("add_timed", scene, time); } } -void CharacterSkeleton3D::common_attach_point_remove_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene) { +void CharacterSkeleton3D::common_attach_point_remove(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene) { int index = common_attach_point_index_get(point); ERR_FAIL_INDEX(index, _attach_point_nodes.size()); Node *n = _attach_point_nodes[index].node; - if (INSTANCE_VALIDATE(n) && n->has_method("remove_effect")) { - n->call("remove_effect", scene); + if (INSTANCE_VALIDATE(n) && n->has_method("remove")) { + n->call("remove", scene); } } int CharacterSkeleton3D::common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point) { @@ -239,6 +239,20 @@ void CharacterSkeleton3D::add_model_visual_entry(Ref vis, Refget_type() == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT) { + EntityEnums::CommonCharacterSkeletonPoints target_bone = static_cast(ive->get_bone()); + + for (int i = 0; i < ive->get_size(); ++i) { + Ref ps = ive->get_attachment(i); + + if (ps.is_valid()) { + common_attach_point_add(target_bone, ps); + } + } + + return; + } + int target_bone_idx = ive->get_bone(); Vector > &entries = _entries.write[target_bone_idx]; @@ -267,6 +281,20 @@ void CharacterSkeleton3D::remove_model_visual_entry(Ref vis, Refget_type() == ModelVisualEntry::MODEL_VISUAL_ENTRY_TYPE_ATTACHMENT) { + EntityEnums::CommonCharacterSkeletonPoints target_bone = static_cast(ive->get_bone()); + + for (int i = 0; i < ive->get_size(); ++i) { + Ref ps = ive->get_attachment(i); + + if (ps.is_valid()) { + common_attach_point_remove(target_bone, ps); + } + } + + return; + } + int target_bone_idx = ive->get_bone(); Vector > &entries = _entries.write[target_bone_idx]; @@ -555,9 +583,9 @@ void CharacterSkeleton3D::_bind_methods() { BIND_VMETHOD(MethodInfo("_common_attach_point_index_get", PropertyInfo(Variant::INT, "point", PROPERTY_HINT_NONE, EntityEnums::BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS))); ClassDB::bind_method(D_METHOD("common_attach_point_node_get", "point"), &CharacterSkeleton3D::common_attach_point_node_get); - ClassDB::bind_method(D_METHOD("common_attach_point_add_effect", "point", "scene"), &CharacterSkeleton3D::common_attach_point_add_effect); - ClassDB::bind_method(D_METHOD("common_attach_point_add_effect_timed", "point", "scene", "time"), &CharacterSkeleton3D::common_attach_point_add_effect_timed); - ClassDB::bind_method(D_METHOD("common_attach_point_remove_effect", "point", "scene"), &CharacterSkeleton3D::common_attach_point_remove_effect); + ClassDB::bind_method(D_METHOD("common_attach_point_add", "point", "scene"), &CharacterSkeleton3D::common_attach_point_add); + ClassDB::bind_method(D_METHOD("common_attach_point_add_timed", "point", "scene", "time"), &CharacterSkeleton3D::common_attach_point_add_timed); + ClassDB::bind_method(D_METHOD("common_attach_point_remove", "point", "scene"), &CharacterSkeleton3D::common_attach_point_remove); ClassDB::bind_method(D_METHOD("common_attach_point_index_get", "point"), &CharacterSkeleton3D::common_attach_point_index_get); ClassDB::bind_method(D_METHOD("_common_attach_point_index_get", "point"), &CharacterSkeleton3D::_common_attach_point_index_get); diff --git a/skeleton/character_skeleton_3d.h b/skeleton/character_skeleton_3d.h index 9f9824a..be501d7 100644 --- a/skeleton/character_skeleton_3d.h +++ b/skeleton/character_skeleton_3d.h @@ -69,9 +69,9 @@ public: int attach_point_count() const; Node *common_attach_point_node_get(const EntityEnums::CommonCharacterSkeletonPoints point); - void common_attach_point_add_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene); - void common_attach_point_add_effect_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene, const float time); - void common_attach_point_remove_effect(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene); + void common_attach_point_add(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene); + void common_attach_point_add_timed(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene, const float time); + void common_attach_point_remove(const EntityEnums::CommonCharacterSkeletonPoints point, const Ref &scene); int common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point); virtual int _common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point);