From 68a674da8c6f512b05bc8e0f620e28a3ac5ed504 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 16 Jun 2020 13:38:33 +0200 Subject: [PATCH] Reimplemented attach points into CharacterSkeleton3D. Also added the CommonCharacterSkeletonPoints enum into EntityEnums, and a customizable skeleton bone attachment points string array into the ProjectSettings, and ESS singleton. --- entity_enums.cpp | 17 +++ entity_enums.h | 22 ++- singletons/ess.cpp | 24 ++++ singletons/ess.h | 7 + skeleton/character_skeleton_3d.cpp | 209 ++++++++++++++++++++--------- skeleton/character_skeleton_3d.h | 36 ++++- 6 files changed, 245 insertions(+), 70 deletions(-) diff --git a/entity_enums.cpp b/entity_enums.cpp index 30fcd35..80b2052 100644 --- a/entity_enums.cpp +++ b/entity_enums.cpp @@ -27,6 +27,7 @@ const String EntityEnums::BINDING_STRING_ENTITY_CONTOLLER = "None,Player,AI"; const String EntityEnums::BINDING_STRING_ENTITY_FLAGS = "Untargetable,Hidden,Interactable,Hostile"; const String EntityEnums::BINDING_STRING_ENTITY_STATE_TYPES = "None,Stun,Root,Frozen,Silenced,Disoriented,Feared,Burning,Cold,Cursed,Pacified"; const String EntityEnums::BINDING_STRING_CHARCATER_SKELETON_POINTS = "Root,Pelvis,Spine,Spine 1,Spine 2,Neck,Head,Left Clavicle,Left upper Arm,Left Forearm,Left Hand,Left Thumb Base,Left Thumb End,Left Fingers Base,Left Fingers End,Right Clavicle,Right upper Arm,Right Forearm,Right Hand,Right Thumb Base,Right Thumb End,Right Fingers Base,Right Fingers End,Left Thigh,Left Calf,Left Foot,Right Thigh,Right Calf,Right Foot"; +const String EntityEnums::BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS = "Root,Pelvis,Spine,Spine 1,Spine 2,Neck,Head,Torso,Right Hip,Left Hip,Back,Left Hand,Right Hand"; const String EntityEnums::BINDING_STRING_AI_STATES = "Off,Rest,Patrol,Follow Path,Regenerate,Attack,Pet Follow,Pet Stop,Pet Attack"; const String EntityEnums::BINDING_STRING_ENTITY_IMMUNITY_FLAGS = "Stun,Root,Freeze,Silence,Disorient,Fear,Burning,Cold,Pacify,Magic,Poison,Physical,Curse,Bleed,Melee,Holy,Shadow,Nature,Fire,Frost,Lightning,Chaos,Slow,Crit,AOE,Damage,Fall Damage,Projectile,Debuff,Attacks"; const String EntityEnums::BINDING_STRING_ENTITY_RELATION_TYPE = "Neutral,Friendly,Hostile"; @@ -77,6 +78,22 @@ void EntityEnums::_bind_methods() { BIND_ENUM_CONSTANT(ENTITY_STATE_TYPE_INDEX_PACIFIED); BIND_ENUM_CONSTANT(ENTITY_STATE_TYPE_INDEX_MAX); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_ROOT); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_PELVIS); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_SPINE); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_SPINE_1); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_SPINE_2); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_NECK); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_HEAD); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_TORSO); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_RIGHT_HIP); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_LEFT_HIP); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_BACK); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_LEFT_HAND); + BIND_ENUM_CONSTANT(COMMON_SKELETON_POINT_RIGHT_HAND); + + BIND_CONSTANT(COMMON_SKELETON_POINTS_MAX); + BIND_ENUM_CONSTANT(SKELETON_POINT_ROOT); BIND_ENUM_CONSTANT(SKELETON_POINT_PELVIS); BIND_ENUM_CONSTANT(SKELETON_POINT_SPINE); diff --git a/entity_enums.h b/entity_enums.h index bcebd10..f7b7c4b 100644 --- a/entity_enums.h +++ b/entity_enums.h @@ -35,6 +35,7 @@ public: static const String BINDING_STRING_ENTITY_FLAGS; static const String BINDING_STRING_ENTITY_STATE_TYPES; static const String BINDING_STRING_CHARCATER_SKELETON_POINTS; + static const String BINDING_STRING_COMMON_CHARCATER_SKELETON_POINTS; static const String BINDING_STRING_AI_STATES; static const String BINDING_STRING_PET_STATES; static const String BINDING_STRING_ENTITY_IMMUNITY_FLAGS; @@ -163,8 +164,24 @@ public: ENTITY_IMMUNITY_FLAG_DISPELL = 1 << 30, }; - //This should only be a common bone lookup enum, that can be made to work for all skeletons - //e.g. for applying spell effects + enum CommonCharacterSkeletonPoints { + COMMON_SKELETON_POINT_ROOT = 0, + COMMON_SKELETON_POINT_PELVIS, + COMMON_SKELETON_POINT_SPINE, + COMMON_SKELETON_POINT_SPINE_1, + COMMON_SKELETON_POINT_SPINE_2, + COMMON_SKELETON_POINT_NECK, + COMMON_SKELETON_POINT_HEAD, + COMMON_SKELETON_POINT_TORSO, + COMMON_SKELETON_POINT_RIGHT_HIP, + COMMON_SKELETON_POINT_LEFT_HIP, + COMMON_SKELETON_POINT_BACK, + COMMON_SKELETON_POINT_LEFT_HAND, + COMMON_SKELETON_POINT_RIGHT_HAND, + + COMMON_SKELETON_POINTS_MAX, + }; + enum CharacterSkeletonPoints { SKELETON_POINT_ROOT = 0, SKELETON_POINT_PELVIS = 1, @@ -269,6 +286,7 @@ VARIANT_ENUM_CAST(EntityEnums::EntityFlags); VARIANT_ENUM_CAST(EntityEnums::EntityStateTypeFlags); VARIANT_ENUM_CAST(EntityEnums::EntityStateTypeIndexes); VARIANT_ENUM_CAST(EntityEnums::CharacterSkeletonPoints); +VARIANT_ENUM_CAST(EntityEnums::CommonCharacterSkeletonPoints); VARIANT_ENUM_CAST(EntityEnums::AIStates); VARIANT_ENUM_CAST(EntityEnums::EntityImmunityFlags); VARIANT_ENUM_CAST(EntityEnums::EntityRelationType); diff --git a/singletons/ess.cpp b/singletons/ess.cpp index 1ce73de..f4121f1 100644 --- a/singletons/ess.cpp +++ b/singletons/ess.cpp @@ -445,6 +445,22 @@ void ESS::skeletons_bones_set(const PoolStringArray &value) { _skeletons_bones = value; } +String ESS::skeletons_bone_attachment_index_get(const int index) const { + ERR_FAIL_INDEX_V(index, _skeletons_bone_attachment_points.size(), String()); + + return _skeletons_bone_attachment_points[index]; +} +int ESS::skeletons_bone_attachments_count() { + return _skeletons_bone_attachment_points.size(); +} + +PoolStringArray ESS::skeletons_bone_attachment_points_get() const { + return _skeletons_bone_attachment_points; +} +void ESS::skeletons_bone_attachment_points_set(const PoolStringArray &value) { + _skeletons_bone_attachment_points = value; +} + //Other String ESS::model_visual_groups_get() const { return _model_visual_groups; @@ -608,6 +624,13 @@ void ESS::_bind_methods() { ClassDB::bind_method(D_METHOD("skeletons_bones_set", "value"), &ESS::skeletons_bones_set); ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "skeletons_bones"), "skeletons_bones_set", "skeletons_bones_get"); + ClassDB::bind_method(D_METHOD("skeletons_bone_attachment_index_get", "index"), &ESS::skeletons_bone_attachment_index_get); + ClassDB::bind_method(D_METHOD("skeletons_bone_attachments_count"), &ESS::skeletons_bone_attachments_count); + + ClassDB::bind_method(D_METHOD("skeletons_bone_attachment_points_get"), &ESS::skeletons_bone_attachment_points_get); + ClassDB::bind_method(D_METHOD("skeletons_bone_attachment_points_set", "value"), &ESS::skeletons_bone_attachment_points_set); + ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "skeletons_bone_attachment_points"), "skeletons_bone_attachment_points_set", "skeletons_bone_attachment_points_get"); + //Other ClassDB::bind_method(D_METHOD("model_visual_groups_get"), &ESS::model_visual_groups_get); ClassDB::bind_method(D_METHOD("model_visual_groups_set", "value"), &ESS::model_visual_groups_set); @@ -646,6 +669,7 @@ ESS::ESS() { _entity_types = GLOBAL_DEF("ess/enums/entity_types", "None,Creature,Totem,Idol,Humanoid,Mechanical,Beast,Dragonkin,Elemental,Ghost,Energy,Anomaly,Demon,Object"); _skeletons_bones = GLOBAL_DEF("ess/enums/skeletons_bones", PoolStringArray()); + _skeletons_bone_attachment_points = GLOBAL_DEF("ess/enums/skeletons_bone_attachment_points", PoolStringArray()); _model_visual_groups = GLOBAL_DEF("ess/enums/model_visual_groups", "None,Bodypart,Alt Bodypart,Attachment"); diff --git a/singletons/ess.h b/singletons/ess.h index 87da85a..ad43861 100644 --- a/singletons/ess.h +++ b/singletons/ess.h @@ -149,6 +149,12 @@ public: PoolStringArray skeletons_bones_get() const; void skeletons_bones_set(const PoolStringArray &value); + String skeletons_bone_attachment_index_get(const int index) const; + int skeletons_bone_attachments_count(); + + PoolStringArray skeletons_bone_attachment_points_get() const; + void skeletons_bone_attachment_points_set(const PoolStringArray &value); + //Other String model_visual_groups_get() const; void model_visual_groups_set(const String &value); @@ -216,6 +222,7 @@ private: //Entity Types String _entity_types; PoolStringArray _skeletons_bones; + PoolStringArray _skeletons_bone_attachment_points; //Other String _model_visual_groups; diff --git a/skeleton/character_skeleton_3d.cpp b/skeleton/character_skeleton_3d.cpp index d99c68e..0de2c30 100644 --- a/skeleton/character_skeleton_3d.cpp +++ b/skeleton/character_skeleton_3d.cpp @@ -22,10 +22,21 @@ SOFTWARE. #include "character_skeleton_3d.h" +#include "../singletons/ess.h" + #include "../data/items/model_visual.h" #include "../defines.h" +int CharacterSkeleton3D::get_entity_type() const { + return _entity_type; +} +void CharacterSkeleton3D::set_entity_type(const int value) { + _entity_type = value; + + _attach_point_nodes.resize(ESS::get_singleton()->skeletons_bone_attachment_index_get(_entity_type).get_slice_count(",")); +} + int CharacterSkeleton3D::get_model_index() { return _model_index; } @@ -40,21 +51,71 @@ void CharacterSkeleton3D::set_model_dirty(bool value) { _model_dirty = value; } -NodePath CharacterSkeleton3D::get_bone_path(int index) { - ERR_FAIL_INDEX_V(index, EntityEnums::SKELETON_POINTS_MAX, NodePath()); +NodePath CharacterSkeleton3D::attach_point_path_get(const int index) const { + ERR_FAIL_INDEX_V(index, _attach_point_nodes.size(), NodePath()); - return _bone_paths[index]; + return _attach_point_nodes[index].path; } -void CharacterSkeleton3D::set_bone_path(int index, NodePath path) { - ERR_FAIL_INDEX(index, EntityEnums::SKELETON_POINTS_MAX); +void CharacterSkeleton3D::attach_point_path_set(const int index, const NodePath &path) { + ERR_FAIL_INDEX(index, _attach_point_nodes.size()); - _bone_paths[index] = path; - - _bone_nodes[index] = get_node_or_null(path); + _attach_point_nodes.write[index].path = path; + _attach_point_nodes.write[index].node = get_node_or_null(path); } -Node *CharacterSkeleton3D::get_bone_node(EntityEnums::CharacterSkeletonPoints node_id) { - return _bone_nodes[node_id]; +Node *CharacterSkeleton3D::attach_point_node_get(const int index) { + ERR_FAIL_INDEX_V(index, _attach_point_nodes.size(), NULL); + + return _attach_point_nodes[index].node; +} + +int CharacterSkeleton3D::attach_point_count() const { + return _attach_point_nodes.size(); +} + +Node *CharacterSkeleton3D::common_attach_point_node_get(const EntityEnums::CommonCharacterSkeletonPoints index) { + ERR_FAIL_INDEX_V(common_attach_point_index_get(index), _attach_point_nodes.size(), NULL); + + 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) { + 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); + } +} +void CharacterSkeleton3D::common_attach_point_add_effect_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); + } +} +void CharacterSkeleton3D::common_attach_point_remove_effect(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); + } +} +int CharacterSkeleton3D::common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point) { + return call("_common_attach_point_index_get", point); +} +int CharacterSkeleton3D::_common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point) { + return 0; } NodePath CharacterSkeleton3D::get_animation_player_path() { @@ -98,8 +159,8 @@ AnimationTree *CharacterSkeleton3D::get_animation_tree() { } void CharacterSkeleton3D::update_nodes() { - for (int i = 0; i < EntityEnums::SKELETON_POINTS_MAX; ++i) { - _bone_nodes[i] = get_node_or_null(_bone_paths[i]); + for (int i = 0; i < _attach_point_nodes.size(); ++i) { + _attach_point_nodes.write[i].node = get_node_or_null(_attach_point_nodes[i].path); } set_animation_player_path(_animation_player_path); @@ -352,15 +413,14 @@ Array CharacterSkeleton3D::bake_mesh_array_uv(Array arr, Ref tex, float CharacterSkeleton3D::CharacterSkeleton3D() { _model_dirty = false; _model_index = 0; - - for (int i = 0; i < EntityEnums::SKELETON_POINTS_MAX; ++i) { - _bone_nodes[i] = NULL; - } + _entity_type = 0; _animation_player = NULL; } CharacterSkeleton3D::~CharacterSkeleton3D() { + _attach_point_nodes.clear(); + for (int i = 0; i < EntityEnums::SKELETON_POINTS_MAX; ++i) { _entries[i].clear(); } @@ -382,7 +442,65 @@ void CharacterSkeleton3D::_notification(int p_what) { } } +bool CharacterSkeleton3D::_set(const StringName &p_name, const Variant &p_value) { + String name = p_name; + + if (name.begins_with("attach_point_paths")) { + int index = name.get_slicec('/', 1).get_slicec('_', 0).to_int(); + + if (index >= _attach_point_nodes.size()) { + _attach_point_nodes.resize(index + 1); + } + + NodePath np = p_value; + + _attach_point_nodes.write[index].path = np; + + if (is_inside_tree()) + _attach_point_nodes.write[index].node = get_node_or_null(p_value); + + return true; + } + + return false; +} +bool CharacterSkeleton3D::_get(const StringName &p_name, Variant &r_ret) const { + String name = p_name; + + if (name.begins_with("attach_point_paths")) { + int index = name.get_slicec('/', 1).get_slicec('_', 0).to_int(); + + if (index >= _attach_point_nodes.size()) { + return false; + } + + r_ret = _attach_point_nodes[index].path; + + return true; + } + + return false; +} +void CharacterSkeleton3D::_get_property_list(List *p_list) const { + String bones = ESS::get_singleton()->skeletons_bone_attachment_index_get(_entity_type); + int slicec = bones.get_slice_count(","); + + for (int i = 0; i < slicec; ++i) { + p_list->push_back(PropertyInfo(Variant::NODE_PATH, "attach_point_paths/" + itos(i) + "_" + bones.get_slicec(',', i))); + } +} + +void CharacterSkeleton3D::_validate_property(PropertyInfo &property) const { + if (property.name == "entity_type") { + property.hint_string = ESS::get_singleton()->entity_types_get(); + } +} + void CharacterSkeleton3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_entity_type"), &CharacterSkeleton3D::get_entity_type); + ClassDB::bind_method(D_METHOD("set_entity_type", "value"), &CharacterSkeleton3D::set_entity_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_type", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_entity_type", "get_entity_type"); + ClassDB::bind_method(D_METHOD("get_model_index"), &CharacterSkeleton3D::get_model_index); ClassDB::bind_method(D_METHOD("set_model_index", "value"), &CharacterSkeleton3D::set_model_index); ADD_PROPERTY(PropertyInfo(Variant::INT, "model_index"), "set_model_index", "get_model_index"); @@ -422,57 +540,24 @@ void CharacterSkeleton3D::_bind_methods() { ClassDB::bind_method(D_METHOD("bake_mesh_array_uv", "arr", "tex", "mul_color"), &CharacterSkeleton3D::bake_mesh_array_uv, DEFVAL(0.7)); //Bone Paths - ClassDB::bind_method(D_METHOD("get_bone_path", "index"), &CharacterSkeleton3D::get_bone_path); - ClassDB::bind_method(D_METHOD("set_bone_path", "index", "path"), &CharacterSkeleton3D::set_bone_path); + ClassDB::bind_method(D_METHOD("attach_point_path_get", "index"), &CharacterSkeleton3D::attach_point_path_get); + ClassDB::bind_method(D_METHOD("attach_point_path_set", "index", "path"), &CharacterSkeleton3D::attach_point_path_set); - //ADD_GROUP("Bone Paths", "bone_path_"); - //ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_root"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_ROOT); + ClassDB::bind_method(D_METHOD("attach_point_node_get", "index"), &CharacterSkeleton3D::attach_point_node_get); - ClassDB::bind_method(D_METHOD("get_bone_node", "bone_idx"), &CharacterSkeleton3D::get_bone_node); + ClassDB::bind_method(D_METHOD("attach_point_count"), &CharacterSkeleton3D::attach_point_count); + + 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_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); ClassDB::bind_method(D_METHOD("get_animation_player"), &CharacterSkeleton3D::get_animation_player); ClassDB::bind_method(D_METHOD("get_animation_tree"), &CharacterSkeleton3D::get_animation_tree); ClassDB::bind_method(D_METHOD("update_nodes"), &CharacterSkeleton3D::update_nodes); - - /* - //Attack Points? - ClassDB::bind_method(D_METHOD("get_visual", "index"), &CharacterSkeleton3D::get_visual); - ClassDB::bind_method(D_METHOD("set_visual", "index", "entry"), &CharacterSkeleton3D::set_visual); - - ADD_GROUP("Visuals", "visual_"); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_root", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_ROOT); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_pelvis", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_PELVIS); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_spine", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_SPINE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_spine_1", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_SPINE_1); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_spine_2", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_SPINE_2); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_neck", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_NECK); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_head", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_HEAD); - - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_clavicle", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_CLAVICLE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_upper_arm", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_UPPER_ARM); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_forearm", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_FOREARM); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_hand", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_HAND); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_thumb_base", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_THUMB_BASE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_thumb_end", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_THUMB_END); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_fingers_base", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_FINGERS_BASE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_fingers_end", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_FINGERS_END); - - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_clavicle", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_CLAVICLE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_upper_arm", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_UPPER_ARM); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_forearm", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_FOREARM); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_hand", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_HAND); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_thumb_base", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_THUMB_BASE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_thumb_end", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_THUMB_END); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_fingers_base", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_FINGERS_BASE); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_fingers_end", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_FINGERS_END); - - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_thigh", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_THIGH); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_calf", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_CALF); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_left_foot", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_LEFT_FOOT); - - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_thigh", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_THIGH); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_calf", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_CALF); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "visual_right_foot", PROPERTY_HINT_RESOURCE_TYPE, "CharacterSkeletonVisualEntry"), "set_visual", "get_visual", EntityEnums::SKELETON_POINT_RIGHT_FOOT); - */ } diff --git a/skeleton/character_skeleton_3d.h b/skeleton/character_skeleton_3d.h index bbe41f2..e4a60df 100644 --- a/skeleton/character_skeleton_3d.h +++ b/skeleton/character_skeleton_3d.h @@ -52,16 +52,28 @@ class CharacterSkeleton3D : public Spatial { GDCLASS(CharacterSkeleton3D, Spatial); public: + int get_entity_type() const; + void set_entity_type(const int value); + int get_model_index(); void set_model_index(int value); bool get_model_dirty() const; void set_model_dirty(bool value); - NodePath get_bone_path(int index); - void set_bone_path(int index, NodePath path); + NodePath attach_point_path_get(const int index) const; + void attach_point_path_set(const int index, const NodePath &path); - Node *get_bone_node(EntityEnums::CharacterSkeletonPoints node_id); + Node *attach_point_node_get(const int index); + + 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); + int common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point); + virtual int _common_attach_point_index_get(const EntityEnums::CommonCharacterSkeletonPoints point); NodePath get_animation_player_path(); void set_animation_player_path(NodePath path); @@ -100,6 +112,10 @@ public: ~CharacterSkeleton3D(); protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + void _validate_property(PropertyInfo &property) const; static void _bind_methods(); virtual void _notification(int p_notification); @@ -114,17 +130,25 @@ protected: } }; + struct AttachPointNode { + NodePath path; + Node *node; + + AttachPointNode() { + node = NULL; + } + }; + private: + int _entity_type; int _model_index; NodePath _animation_player_path; NodePath _animation_tree_path; - NodePath _bone_paths[EntityEnums::SKELETON_POINTS_MAX]; - AnimationPlayer *_animation_player; AnimationTree *_animation_tree; - Node *_bone_nodes[EntityEnums::SKELETON_POINTS_MAX]; + Vector _attach_point_nodes; bool _model_dirty; Vector > _model_visuals;