diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-08 12:29:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-08 12:29:49 +0300 |
commit | 97b6948181df4ee97296ec45aebc75f31b7c790a (patch) | |
tree | f2dbe2c2ba99abb1a0ee832268bb97d6fd4a4a22 /source/blender/blenkernel/intern | |
parent | 5eb500f2fce12f0b9a042480d0d4bf5000907726 (diff) |
Fix T46386: Duplicate fails updating driver links
Duplicate wasn't updating links,
so duplicatinvg a objects would still point to the originals for curve-taper, texmesh, drivers.
Use generic id-looper to handle replacing data.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 26 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library_query.c | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 32 |
3 files changed, 43 insertions, 32 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 9fb0cb42dfc..d6b2a3cea29 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -95,6 +95,7 @@ #include "BKE_lamp.h" #include "BKE_lattice.h" #include "BKE_library.h" +#include "BKE_library_query.h" #include "BKE_linestyle.h" #include "BKE_mesh.h" #include "BKE_material.h" @@ -864,6 +865,31 @@ void *BKE_libblock_copy(ID *id) return BKE_libblock_copy_ex(G.main, id); } +static bool id_relink_looper(void *UNUSED(user_data), ID **id_pointer, const int cd_flag) +{ + ID *id = *id_pointer; + if (id) { + /* See: NEW_ID macro */ + if (id->newid) { + BKE_library_update_ID_link_user(id->newid, id, cd_flag); + *id_pointer = id->newid; + } + else if (id->flag & LIB_NEW) { + id->flag &= ~LIB_NEW; + BKE_libblock_relink(id); + } + } + return true; +} + +void BKE_libblock_relink(ID *id) +{ + if (id->lib) + return; + + BKE_library_foreach_ID_link(id, id_relink_looper, NULL, 0); +} + static void BKE_library_free(Library *lib) { if (lib->packedfile) diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index 4e78c7b5049..b59d0cf5b6d 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -62,6 +62,7 @@ #include "BKE_animsys.h" #include "BKE_constraint.h" #include "BKE_fcurve.h" +#include "BKE_library.h" #include "BKE_library_query.h" #include "BKE_modifier.h" #include "BKE_particle.h" @@ -534,3 +535,19 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u #undef FOREACH_CALLBACK_INVOKE_ID #undef FOREACH_CALLBACK_INVOKE + +/** + * re-usable function, use when replacing ID's + */ +void BKE_library_update_ID_link_user(ID *id_dst, ID *id_src, const int cd_flag) +{ + if (cd_flag & IDWALK_USER) { + id_us_min(id_src); + id_us_plus(id_dst); + } + else if (cd_flag & IDWALK_USER_ONE) { + if (id_dst->us == 0) { + id_us_plus(id_dst); + } + } +}
\ No newline at end of file diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 0c9239e3ddf..fb4b0a99d0a 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -3722,38 +3722,6 @@ bool BKE_object_is_animated(Scene *scene, Object *ob) return false; } -static void copy_object__forwardModifierLinks(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin) -{ - /* this is copied from ID_NEW; it might be better to have a macro */ - if (*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid; -} - -void BKE_object_relink(Object *ob) -{ - if (ob->id.lib) - return; - - BKE_constraints_relink(&ob->constraints); - if (ob->pose) { - bPoseChannel *chan; - for (chan = ob->pose->chanbase.first; chan; chan = chan->next) { - BKE_constraints_relink(&chan->constraints); - } - } - modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL); - - if (ob->adt) - BKE_animdata_relink(ob->adt); - - if (ob->rigidbody_constraint) - BKE_rigidbody_relink_constraint(ob->rigidbody_constraint); - - ID_NEW(ob->parent); - - ID_NEW(ob->proxy); - ID_NEW(ob->proxy_group); -} - MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default) { MovieClip *clip = use_default ? scene->clip : NULL; |