From 57daecc2cf88878e56394726759c48f81610806a Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 6 Mar 2020 16:03:00 +0100 Subject: Cleanup: Armature: Move to IDTypeInfo, and remove unused BKE API. --- source/blender/blenkernel/BKE_armature.h | 6 - source/blender/blenkernel/BKE_idtype.h | 2 +- source/blender/blenkernel/intern/armature.c | 162 +++++++++++++---------- source/blender/blenkernel/intern/idtype.c | 2 +- source/blender/blenkernel/intern/lib_id.c | 6 +- source/blender/blenkernel/intern/lib_id_delete.c | 2 +- 6 files changed, 99 insertions(+), 81 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 86d8362f5e6..cd4733a4e62 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -67,12 +67,6 @@ struct bArmature *BKE_armature_add(struct Main *bmain, const char *name); struct bArmature *BKE_armature_from_object(struct Object *ob); int BKE_armature_bonelist_count(struct ListBase *lb); void BKE_armature_bonelist_free(struct ListBase *lb); -void BKE_armature_free(struct bArmature *arm); -void BKE_armature_make_local(struct Main *bmain, struct bArmature *arm, const int flags); -void BKE_armature_copy_data(struct Main *bmain, - struct bArmature *arm_dst, - const struct bArmature *arm_src, - const int flag); struct bArmature *BKE_armature_copy(struct Main *bmain, const struct bArmature *arm); void BKE_armature_copy_bone_transforms(struct bArmature *armature_dst, diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index 57782e58954..0e726828d1a 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -145,7 +145,7 @@ extern IDTypeInfo IDType_ID_SCR; // extern IDTypeInfo IDType_ID_SPK; // extern IDTypeInfo IDType_ID_SO; extern IDTypeInfo IDType_ID_GR; -// extern IDTypeInfo IDType_ID_AR; +extern IDTypeInfo IDType_ID_AR; // extern IDTypeInfo IDType_ID_AC; extern IDTypeInfo IDType_ID_NT; extern IDTypeInfo IDType_ID_BR; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index f48f29406e3..6f0b5fb7421 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -37,6 +37,7 @@ #include "BLI_task.h" #include "BLI_utildefines.h" #include "BLI_alloca.h" +#include "BLT_translation.h" #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -58,6 +59,7 @@ #include "BKE_deform.h" #include "BKE_displist.h" #include "BKE_idprop.h" +#include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_lattice.h" #include "BKE_main.h" @@ -74,6 +76,98 @@ static CLG_LogRef LOG = {"bke.armature"}; +/*************************** Prototypes ***************************/ + +static void copy_bonechildren(Bone *bone_dst, + const Bone *bone_src, + const Bone *bone_src_act, + Bone **r_bone_dst_act, + const int flag); + +static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst); + +/*********************** Armature Datablock ***********************/ + +/** + * Only copy internal data of Armature ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. + * + * WARNING! This function will not handle ID user count! + * + * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). + */ +static void armature_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag) +{ + bArmature *armature_dst = (bArmature *)id_dst; + const bArmature *armature_src = (const bArmature *)id_src; + + Bone *bone_src, *bone_dst; + Bone *bone_dst_act = NULL; + + /* We never handle usercount here for own data. */ + const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; + + armature_dst->bonehash = NULL; + + BLI_duplicatelist(&armature_dst->bonebase, &armature_src->bonebase); + + /* Duplicate the childrens' lists */ + bone_dst = armature_dst->bonebase.first; + for (bone_src = armature_src->bonebase.first; bone_src; bone_src = bone_src->next) { + bone_dst->parent = NULL; + copy_bonechildren(bone_dst, bone_src, armature_src->act_bone, &bone_dst_act, flag_subdata); + bone_dst = bone_dst->next; + } + + armature_dst->act_bone = bone_dst_act; + + BKE_armature_bone_hash_make(armature_dst); + + /* Fix custom handle references. */ + for (bone_dst = armature_dst->bonebase.first; bone_dst; bone_dst = bone_dst->next) { + copy_bonechildren_custom_handles(bone_dst, armature_dst); + } + + armature_dst->edbo = NULL; + armature_dst->act_edbone = NULL; +} + +/** Free (or release) any data used by this armature (does not free the armature itself). */ +static void armature_free_data(struct ID *id) +{ + bArmature *armature = (bArmature *)id; + BKE_animdata_free(&armature->id, false); + + BKE_armature_bone_hash_free(armature); + BKE_armature_bonelist_free(&armature->bonebase); + + /* free editmode data */ + if (armature->edbo) { + BLI_freelistN(armature->edbo); + + MEM_freeN(armature->edbo); + armature->edbo = NULL; + } +} + +IDTypeInfo IDType_ID_AR = { + .id_code = ID_AR, + .id_filter = FILTER_ID_AR, + .main_listbase_index = INDEX_ID_AR, + .struct_size = sizeof(bArmature), + .name = "Armature", + .name_plural = "armature", + .translation_context = BLT_I18NCONTEXT_ID_ARMATURE, + .flags = 0, + + .init_data = NULL, + .copy_data = armature_copy_data, + .free_data = armature_free_data, + .make_local = NULL, +}; + /* **************** Generic Functions, data level *************** */ bArmature *BKE_armature_add(Main *bmain, const char *name) @@ -119,28 +213,6 @@ void BKE_armature_bonelist_free(ListBase *lb) BLI_freelistN(lb); } -/** Free (or release) any data used by this armature (does not free the armature itself). */ -void BKE_armature_free(bArmature *arm) -{ - BKE_animdata_free(&arm->id, false); - - BKE_armature_bone_hash_free(arm); - BKE_armature_bonelist_free(&arm->bonebase); - - /* free editmode data */ - if (arm->edbo) { - BLI_freelistN(arm->edbo); - - MEM_freeN(arm->edbo); - arm->edbo = NULL; - } -} - -void BKE_armature_make_local(Main *bmain, bArmature *arm, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, &arm->id, flags); -} - static void copy_bonechildren(Bone *bone_dst, const Bone *bone_src, const Bone *bone_src_act, @@ -186,52 +258,6 @@ static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst) } } -/** - * Only copy internal data of Armature ID from source - * to already allocated/initialized destination. - * You probably never want to use that directly, - * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. - * - * WARNING! This function will not handle ID user count! - * - * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). - */ -void BKE_armature_copy_data(Main *UNUSED(bmain), - bArmature *arm_dst, - const bArmature *arm_src, - const int flag) -{ - Bone *bone_src, *bone_dst; - Bone *bone_dst_act = NULL; - - /* We never handle usercount here for own data. */ - const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; - - arm_dst->bonehash = NULL; - - BLI_duplicatelist(&arm_dst->bonebase, &arm_src->bonebase); - - /* Duplicate the childrens' lists */ - bone_dst = arm_dst->bonebase.first; - for (bone_src = arm_src->bonebase.first; bone_src; bone_src = bone_src->next) { - bone_dst->parent = NULL; - copy_bonechildren(bone_dst, bone_src, arm_src->act_bone, &bone_dst_act, flag_subdata); - bone_dst = bone_dst->next; - } - - arm_dst->act_bone = bone_dst_act; - - BKE_armature_bone_hash_make(arm_dst); - - /* Fix custom handle references. */ - for (bone_dst = arm_dst->bonebase.first; bone_dst; bone_dst = bone_dst->next) { - copy_bonechildren_custom_handles(bone_dst, arm_dst); - } - - arm_dst->edbo = NULL; - arm_dst->act_edbone = NULL; -} - bArmature *BKE_armature_copy(Main *bmain, const bArmature *arm) { bArmature *arm_copy; diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index 52d6a699642..a420ab17a26 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -72,7 +72,7 @@ static void id_type_init(void) // INIT_TYPE(ID_SPK); // INIT_TYPE(ID_SO); INIT_TYPE(ID_GR); - // INIT_TYPE(ID_AR); + INIT_TYPE(ID_AR); // INIT_TYPE(ID_AC); INIT_TYPE(ID_NT); INIT_TYPE(ID_BR); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 984610198ee..a60589de503 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -537,9 +537,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags BLI_assert(0); return true; case ID_AR: - if (!test) { - BKE_armature_make_local(bmain, (bArmature *)id, flags); - } + BLI_assert(0); return true; case ID_AC: if (!test) { @@ -757,7 +755,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) BLI_assert(0); break; case ID_AR: - BKE_armature_copy_data(bmain, (bArmature *)*r_newid, (bArmature *)id, flag); + BLI_assert(0); break; case ID_AC: BKE_action_copy_data(bmain, (bAction *)*r_newid, (bAction *)id, flag); diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 183d9407363..583a610b8ae 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -203,7 +203,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BLI_assert(0); break; case ID_AR: - BKE_armature_free((bArmature *)id); + BLI_assert(0); break; case ID_AC: BKE_action_free((bAction *)id); -- cgit v1.2.3