Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/armature.c
| Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | void BKE_armature_free(bArmature *arm) | ||||
| } | } | ||||
| } | } | ||||
| void BKE_armature_make_local(Main *bmain, bArmature *arm, const bool lib_local) | void BKE_armature_make_local(Main *bmain, bArmature *arm, const bool lib_local) | ||||
| { | { | ||||
| BKE_id_make_local_generic(bmain, &arm->id, true, lib_local); | BKE_id_make_local_generic(bmain, &arm->id, true, lib_local); | ||||
| } | } | ||||
| static void copy_bonechildren(Bone *newBone, const Bone *oldBone, const Bone *actBone, Bone **newActBone) | static void copy_bonechildren( | ||||
| Bone *bone_dst, const Bone *bone_src, const Bone *bone_src_act, Bone **r_bone_dst_act, const int flag) | |||||
| { | { | ||||
| Bone *curBone, *newChildBone; | Bone *bone_src_child, *bone_dst_child; | ||||
| if (oldBone == actBone) | if (bone_src == bone_src_act) { | ||||
| *newActBone = newBone; | *r_bone_dst_act = bone_dst; | ||||
| } | |||||
| if (oldBone->prop) | if (bone_src->prop) { | ||||
| newBone->prop = IDP_CopyProperty(oldBone->prop); | bone_dst->prop = IDP_CopyProperty_ex(bone_src->prop, flag); | ||||
| } | |||||
| /* Copy this bone's list */ | /* Copy this bone's list */ | ||||
| BLI_duplicatelist(&newBone->childbase, &oldBone->childbase); | BLI_duplicatelist(&bone_dst->childbase, &bone_src->childbase); | ||||
| /* For each child in the list, update it's children */ | /* For each child in the list, update it's children */ | ||||
| newChildBone = newBone->childbase.first; | for (bone_src_child = bone_src->childbase.first, bone_dst_child = bone_dst->childbase.first; | ||||
| for (curBone = oldBone->childbase.first; curBone; curBone = curBone->next) { | bone_src_child; | ||||
| newChildBone->parent = newBone; | bone_src_child = bone_src_child->next, bone_dst_child = bone_dst_child->next) | ||||
| copy_bonechildren(newChildBone, curBone, actBone, newActBone); | { | ||||
| newChildBone = newChildBone->next; | bone_dst_child->parent = bone_dst; | ||||
| copy_bonechildren(bone_dst_child, bone_src_child, bone_src_act, r_bone_dst_act, flag); | |||||
| } | } | ||||
| } | } | ||||
| bArmature *BKE_armature_copy(Main *bmain, const bArmature *arm) | /** | ||||
| * Only copy internal data of Armature ID from source to already allocated/initialized destination. | |||||
| * You probably nerver want to use that directly, use 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_library.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) | |||||
| { | { | ||||
| bArmature *newArm; | Bone *bone_src, *bone_dst; | ||||
| Bone *oldBone, *newBone; | Bone *bone_dst_act = NULL; | ||||
| Bone *newActBone = NULL; | |||||
| /* We never handle usercount here for own data. */ | |||||
| const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT; | |||||
| newArm = BKE_libblock_copy(bmain, &arm->id); | BLI_duplicatelist(&arm_dst->bonebase, &arm_src->bonebase); | ||||
| BLI_duplicatelist(&newArm->bonebase, &arm->bonebase); | |||||
| /* Duplicate the childrens' lists */ | /* Duplicate the childrens' lists */ | ||||
| newBone = newArm->bonebase.first; | bone_dst = arm_dst->bonebase.first; | ||||
| for (oldBone = arm->bonebase.first; oldBone; oldBone = oldBone->next) { | for (bone_src = arm_src->bonebase.first; bone_src; bone_src = bone_src->next) { | ||||
| newBone->parent = NULL; | bone_dst->parent = NULL; | ||||
| copy_bonechildren(newBone, oldBone, arm->act_bone, &newActBone); | copy_bonechildren(bone_dst, bone_src, arm_src->act_bone, &bone_dst_act, flag_subdata); | ||||
| newBone = newBone->next; | bone_dst = bone_dst->next; | ||||
| } | } | ||||
| newArm->act_bone = newActBone; | arm_dst->act_bone = bone_dst_act; | ||||
| newArm->edbo = NULL; | arm_dst->edbo = NULL; | ||||
| newArm->act_edbone = NULL; | arm_dst->act_edbone = NULL; | ||||
| newArm->sketch = NULL; | arm_dst->sketch = NULL; | ||||
| } | |||||
| BKE_id_copy_ensure_local(bmain, &arm->id, &newArm->id); | |||||
| return newArm; | bArmature *BKE_armature_copy(Main *bmain, const bArmature *arm) | ||||
| { | |||||
| bArmature *arm_copy; | |||||
| BKE_id_copy_ex(bmain, &arm->id, (ID **)&arm_copy, 0, false); | |||||
| return arm_copy; | |||||
| } | } | ||||
| static Bone *get_named_bone_bonechildren(ListBase *lb, const char *name) | static Bone *get_named_bone_bonechildren(ListBase *lb, const char *name) | ||||
| { | { | ||||
| Bone *curBone, *rbone; | Bone *curBone, *rbone; | ||||
| for (curBone = lb->first; curBone; curBone = curBone->next) { | for (curBone = lb->first; curBone; curBone = curBone->next) { | ||||
| if (STREQ(curBone->name, name)) | if (STREQ(curBone->name, name)) | ||||
| ▲ Show 20 Lines • Show All 2,248 Lines • Show Last 20 Lines | |||||