Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/armature.c')
-rw-r--r--source/blender/blenkernel/intern/armature.c59
1 files changed, 24 insertions, 35 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index b59618f46b2..5f564e1c4d2 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -67,6 +67,8 @@
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_library.h"
+#include "BKE_library_query.h"
+#include "BKE_library_remap.h"
#include "BKE_lattice.h"
#include "BKE_main.h"
#include "BKE_object.h"
@@ -142,46 +144,32 @@ void BKE_armature_free(bArmature *arm)
}
}
-void BKE_armature_make_local(bArmature *arm)
+void BKE_armature_make_local(Main *bmain, bArmature *arm)
{
- Main *bmain = G.main;
bool is_local = false, is_lib = false;
- Object *ob;
- if (arm->id.lib == NULL)
- return;
- if (arm->id.us == 1) {
- id_clear_lib_data(bmain, &arm->id);
+ /* - only lib users: do nothing
+ * - only local users: set flag
+ * - mixed: make copy
+ */
+
+ if (!ID_IS_LINKED_DATABLOCK(arm)) {
return;
}
- for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) {
- if (ob->data == arm) {
- if (ob->id.lib)
- is_lib = true;
- else
- is_local = true;
- }
- }
+ BKE_library_ID_test_usages(bmain, arm, &is_local, &is_lib);
- if (is_local && is_lib == false) {
- id_clear_lib_data(bmain, &arm->id);
- }
- else if (is_local && is_lib) {
- bArmature *arm_new = BKE_armature_copy(arm);
- arm_new->id.us = 0;
+ if (is_local) {
+ if (!is_lib) {
+ id_clear_lib_data(bmain, &arm->id);
+ BKE_id_expand_local(&arm->id);
+ }
+ else {
+ bArmature *arm_new = BKE_armature_copy(bmain, arm);
- /* Remap paths of new ID using old library as base. */
- BKE_id_lib_local_paths(bmain, arm->id.lib, &arm_new->id);
+ arm_new->id.us = 0;
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- if (ob->data == arm) {
- if (ob->id.lib == NULL) {
- ob->data = arm_new;
- id_us_plus(&arm_new->id);
- id_us_min(&arm->id);
- }
- }
+ BKE_libblock_remap(bmain, arm, arm_new, ID_REMAP_SKIP_INDIRECT_USAGE);
}
}
}
@@ -208,13 +196,13 @@ static void copy_bonechildren(Bone *newBone, Bone *oldBone, Bone *actBone, Bone
}
}
-bArmature *BKE_armature_copy(bArmature *arm)
+bArmature *BKE_armature_copy(Main *bmain, bArmature *arm)
{
bArmature *newArm;
Bone *oldBone, *newBone;
Bone *newActBone = NULL;
- newArm = BKE_libblock_copy(&arm->id);
+ newArm = BKE_libblock_copy(bmain, &arm->id);
BLI_duplicatelist(&newArm->bonebase, &arm->bonebase);
/* Duplicate the childrens' lists */
@@ -231,8 +219,9 @@ bArmature *BKE_armature_copy(bArmature *arm)
newArm->act_edbone = NULL;
newArm->sketch = NULL;
- if (arm->id.lib) {
- BKE_id_lib_local_paths(G.main, arm->id.lib, &newArm->id);
+ if (ID_IS_LINKED_DATABLOCK(arm)) {
+ BKE_id_expand_local(&newArm->id);
+ BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id);
}
return newArm;