diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_animsys.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_nla.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/anim_sys.c | 25 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 31 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/nla.c | 33 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc | 2 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_relations.c | 4 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 4 | ||||
-rw-r--r-- | source/blender/editors/object/object_relations.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_nla/nla_edit.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_animation.c | 2 |
11 files changed, 65 insertions, 54 deletions
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 9e8e7f7b724..0b7405c64a0 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -70,10 +70,10 @@ bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct b void BKE_animdata_free(struct ID *id, const bool do_id_user); /* Copy AnimData */ -struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const bool do_action, const bool do_id_user); +struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const int flag); /* Copy AnimData */ -bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const bool do_action, const bool do_id_user); +bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const int flag); /* Copy AnimData Actions */ void BKE_animdata_copy_id_action(struct Main *bmain, struct ID *id, const bool set_newid); diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h index 87240885b2c..a42819e52a2 100644 --- a/source/blender/blenkernel/BKE_nla.h +++ b/source/blender/blenkernel/BKE_nla.h @@ -51,9 +51,9 @@ void BKE_nlastrip_free(ListBase *strips, struct NlaStrip *strip, bool do_id_user void BKE_nlatrack_free(ListBase *tracks, struct NlaTrack *nlt, bool do_id_user); void BKE_nla_tracks_free(ListBase *tracks, bool do_id_user); -struct NlaStrip *BKE_nlastrip_copy(struct Main *bmain, struct NlaStrip *strip, const bool use_same_action); -struct NlaTrack *BKE_nlatrack_copy(struct Main *bmain, struct NlaTrack *nlt, const bool use_same_actions); -void BKE_nla_tracks_copy(struct Main *bmain, ListBase *dst, ListBase *src); +struct NlaStrip *BKE_nlastrip_copy(struct Main *bmain, struct NlaStrip *strip, const bool use_same_action, const int flag); +struct NlaTrack *BKE_nlatrack_copy(struct Main *bmain, struct NlaTrack *nlt, const bool use_same_actions, const int flag); +void BKE_nla_tracks_copy(struct Main *bmain, ListBase *dst, ListBase *src, const int flag); struct NlaTrack *BKE_nlatrack_add(struct AnimData *adt, struct NlaTrack *prev); struct NlaStrip *BKE_nlastrip_new(struct bAction *act); diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index b08038f67af..639e4f40004 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -266,11 +266,18 @@ void BKE_animdata_free(ID *id, const bool do_id_user) /* Copying -------------------------------------------- */ -/* Make a copy of the given AnimData - to be used when copying datablocks */ -AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, const bool do_id_user) +/** + * Make a copy of the given AnimData - to be used when copying datablocks. + * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \return The copied animdata. + */ +AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag) { AnimData *dadt; + const bool do_action = (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0; + const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0; + /* sanity check before duplicating struct */ if (adt == NULL) return NULL; @@ -288,7 +295,7 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, co } /* duplicate NLA data */ - BKE_nla_tracks_copy(bmain, &dadt->nla_tracks, &adt->nla_tracks); + BKE_nla_tracks_copy(bmain, &dadt->nla_tracks, &adt->nla_tracks, flag); /* duplicate drivers (F-Curves) */ copy_fcurves(&dadt->drivers, &adt->drivers); @@ -301,19 +308,23 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, co return dadt; } -bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const bool do_action, const bool do_id_user) +/** + * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \return true is succesfully copied. + */ +bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag) { AnimData *adt; if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name))) return false; - BKE_animdata_free(id_to, do_id_user); + BKE_animdata_free(id_to, (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0); adt = BKE_animdata_from_id(id_from); if (adt) { IdAdtTemplate *iat = (IdAdtTemplate *)id_to; - iat->adt = BKE_animdata_copy(bmain, adt, do_action, do_id_user); + iat->adt = BKE_animdata_copy(bmain, adt, flag); } return true; @@ -373,7 +384,7 @@ void BKE_animdata_merge_copy( if (src->nla_tracks.first) { ListBase tracks = {NULL, NULL}; - BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks); + BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks, 0); BLI_movelisttolist(&dst->nla_tracks, &tracks); } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index ff663cfab01..74c3341fa96 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1416,18 +1416,6 @@ void *BKE_id_new_nomain(const short type, const char *name) return id; } -/* by spec, animdata is first item after ID */ -/* and, trust that BKE_animdata_from_id() will only find AnimData for valid ID-types */ -static void id_copy_animdata(Main *bmain, ID *id, const bool do_action, const bool do_id_user) -{ - AnimData *adt = BKE_animdata_from_id(id); - - if (adt) { - IdAdtTemplate *iat = (IdAdtTemplate *)id; - iat->adt = BKE_animdata_copy(bmain, iat->adt, do_action, do_id_user); - } -} - void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) { ID *new_id = *r_newid; @@ -1478,16 +1466,17 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla } #endif - /* the duplicate should get a copy of the animdata */ - if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) { - BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0); - id_copy_animdata(bmain, new_id, - (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0, - (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0); - } - else if (id_can_have_animdata(new_id)) { + if (id_can_have_animdata(new_id)) { IdAdtTemplate *iat = (IdAdtTemplate *)new_id; - iat->adt = NULL; + + /* the duplicate should get a copy of the animdata */ + if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) { + BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0); + iat->adt = BKE_animdata_copy(bmain, iat->adt, flag); + } + else { + iat->adt = NULL; + } } if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0) { diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 8c5cc6f2b38..192e6b5e56e 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -163,12 +163,15 @@ void BKE_nla_tracks_free(ListBase *tracks, bool do_id_user) * Copy NLA strip * * \param use_same_action When true, the existing action is used (instead of being duplicated) + * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h */ -NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_action) +NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_action, const int flag) { NlaStrip *strip_d; NlaStrip *cs, *cs_d; + const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0; + /* sanity check */ if (strip == NULL) return NULL; @@ -180,12 +183,14 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_ac /* handle action */ if (strip_d->act) { if (use_same_action) { - /* increase user-count of action */ - id_us_plus(&strip_d->act->id); + if (do_id_user) { + /* increase user-count of action */ + id_us_plus(&strip_d->act->id); + } } else { /* use a copy of the action instead (user count shouldn't have changed yet) */ - strip_d->act = BKE_action_copy(bmain, strip_d->act); + BKE_id_copy_ex(bmain, &strip_d->act->id, (ID **)&strip_d->act, flag, false); } } @@ -197,7 +202,7 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_ac BLI_listbase_clear(&strip_d->strips); for (cs = strip->strips.first; cs; cs = cs->next) { - cs_d = BKE_nlastrip_copy(bmain, cs, use_same_action); + cs_d = BKE_nlastrip_copy(bmain, cs, use_same_action, flag); BLI_addtail(&strip_d->strips, cs_d); } @@ -205,8 +210,11 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, const bool use_same_ac return strip_d; } -/* Copy NLA Track */ -NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_actions) +/** + * Copy a single NLA Track. + * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + */ +NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_actions, const int flag) { NlaStrip *strip, *strip_d; NlaTrack *nlt_d; @@ -223,7 +231,7 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_acti BLI_listbase_clear(&nlt_d->strips); for (strip = nlt->strips.first; strip; strip = strip->next) { - strip_d = BKE_nlastrip_copy(bmain, strip, use_same_actions); + strip_d = BKE_nlastrip_copy(bmain, strip, use_same_actions, flag); BLI_addtail(&nlt_d->strips, strip_d); } @@ -231,8 +239,11 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, const bool use_same_acti return nlt_d; } -/* Copy all NLA data */ -void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src) +/** + * Copy all NLA data. + * \param flag Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + */ +void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src, const int flag) { NlaTrack *nlt, *nlt_d; @@ -247,7 +258,7 @@ void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src) for (nlt = src->first; nlt; nlt = nlt->next) { /* make a copy, and add the copy to the destination list */ // XXX: we need to fix this sometime - nlt_d = BKE_nlatrack_copy(bmain, nlt, true); + nlt_d = BKE_nlatrack_copy(bmain, nlt, true, flag); BLI_addtail(dst, nlt_d); } } diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index f6c3703a703..c1cbf03a904 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -712,7 +712,7 @@ static void deg_update_copy_on_write_animation(const Depsgraph *depsgraph, __func__, id_node->id_orig->name, id_node->id_cow); - BKE_animdata_copy_id(NULL, id_node->id_cow, id_node->id_orig, false, false); + BKE_animdata_copy_id(NULL, id_node->id_cow, id_node->id_orig, LIB_ID_CREATE_NO_USER_REFCOUNT); RemapCallbackUserData user_data = {NULL}; user_data.depsgraph = depsgraph; BKE_library_foreach_ID_link(NULL, diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index 28fd80bc354..80dc2559bdb 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -373,7 +373,7 @@ int join_armature_exec(bContext *C, wmOperator *op) if (ob_iter->adt) { if (ob_active->adt == NULL) { /* no animdata, so just use a copy of the whole thing */ - ob_active->adt = BKE_animdata_copy(bmain, ob_iter->adt, false, true); + ob_active->adt = BKE_animdata_copy(bmain, ob_iter->adt, 0); } else { /* merge in data - we'll fix the drivers manually */ @@ -384,7 +384,7 @@ int join_armature_exec(bContext *C, wmOperator *op) if (curarm->adt) { if (arm->adt == NULL) { /* no animdata, so just use a copy of the whole thing */ - arm->adt = BKE_animdata_copy(bmain, curarm->adt, false, true); + arm->adt = BKE_animdata_copy(bmain, curarm->adt, 0); } else { /* merge in data - we'll fix the drivers manually */ diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index a9cd868aff3..40cff866ffe 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -2122,7 +2122,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) if (ob_iter->adt) { if (ob_active->adt == NULL) { /* no animdata, so just use a copy of the whole thing */ - ob_active->adt = BKE_animdata_copy(bmain, ob_iter->adt, false, true); + ob_active->adt = BKE_animdata_copy(bmain, ob_iter->adt, 0); } else { /* merge in data - we'll fix the drivers manually */ @@ -2133,7 +2133,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) if (gpd_src->adt) { if (gpd_dst->adt == NULL) { /* no animdata, so just use a copy of the whole thing */ - gpd_dst->adt = BKE_animdata_copy(bmain, gpd_src->adt, false, true); + gpd_dst->adt = BKE_animdata_copy(bmain, gpd_src->adt, 0); } else { /* merge in data - we'll fix the drivers manually */ diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 27cfee95341..42752b76304 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1473,13 +1473,13 @@ static int make_links_data_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA); break; case MAKE_LINKS_ANIMDATA: - BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, false, true); + BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, 0); if (ob_dst->data && ob_src->data) { if (ID_IS_LINKED(obdata_id)) { is_lib = true; break; } - BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, false, true); + BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, 0); } DEG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); break; diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 63de4ec9dea..724a1c072bd 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -1057,7 +1057,7 @@ static int nlaedit_duplicate_exec(bContext *C, wmOperator *op) /* if selected, split the strip at its midpoint */ if (strip->flag & NLASTRIP_FLAG_SELECT) { /* make a copy (assume that this is possible) */ - nstrip = BKE_nlastrip_copy(ac.bmain, strip, linked); + nstrip = BKE_nlastrip_copy(ac.bmain, strip, linked, 0); /* in case there's no space in the track above, or we haven't got a reference to it yet, try adding */ if (BKE_nlatrack_add_strip(nlt->next, nstrip) == 0) { @@ -1242,7 +1242,7 @@ static void nlaedit_split_strip_actclip(Main *bmain, AnimData *adt, NlaTrack *nl /* make a copy (assume that this is possible) and append * it immediately after the current strip */ - nstrip = BKE_nlastrip_copy(bmain, strip, true); + nstrip = BKE_nlastrip_copy(bmain, strip, true, 0); BLI_insertlinkafter(&nlt->strips, strip, nstrip); /* set the endpoint of the first strip and the start of the new strip diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index ee399ee8648..33cf8b581b8 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -603,7 +603,7 @@ bool rna_AnimaData_override_apply( if (adt_dst == NULL && adt_src != NULL) { /* Copy anim data from reference into final local ID. */ - BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, false, true); + BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, 0); return true; } else if (adt_dst != NULL && adt_src == NULL) { |