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:
authorBastien Montagne <montagne29@wanadoo.fr>2018-05-02 12:34:19 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-05-02 12:34:19 +0300
commit43f9b6ba451a5d9feb02fa2e4d01fb9122a9e575 (patch)
tree83b83c8f2a58bdcf4b42d630c8dca31f3c2dbb71 /source/blender/blenkernel
parentc7947b2115bf1b15caed94a67b1b39df1959ebb2 (diff)
Tweak constraint copying code for static override needs.
No expected change in any existing behaviour from this commit.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_constraint.h2
-rw-r--r--source/blender/blenkernel/intern/constraint.c61
2 files changed, 40 insertions, 23 deletions
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index 54ddb61d922..18f6301953c 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -118,6 +118,8 @@ const bConstraintTypeInfo *BKE_constraint_typeinfo_from_type(int type);
/* Constraint function prototypes */
void BKE_constraint_unique_name(struct bConstraint *con, struct ListBase *list);
+struct bConstraint *BKE_constraint_duplicate_ex(struct bConstraint *src, const int flag, const bool do_extern);
+
void BKE_constraints_free(struct ListBase *list);
void BKE_constraints_free_ex(struct ListBase *list, bool do_id_user);
void BKE_constraints_copy(struct ListBase *dst, const struct ListBase *src, bool do_extern);
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index b58028b4a5d..d7c21fc0973 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -4657,6 +4657,43 @@ static void con_fix_copied_refs_cb(bConstraint *UNUSED(con), ID **idpoin, bool i
id_us_plus(*idpoin);
}
+/** Copies a single constraint's data (\a dst must already be a shallow copy of \a src). */
+static void constraint_copy_data_ex(bConstraint *dst, bConstraint *src, const int flag, const bool do_extern)
+{
+ const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(src);
+
+ /* make a new copy of the constraint's data */
+ dst->data = MEM_dupallocN(dst->data);
+
+ /* only do specific constraints if required */
+ if (cti) {
+ /* perform custom copying operations if needed */
+ if (cti->copy_data)
+ cti->copy_data(dst, src);
+
+ /* Fix usercounts for all referenced data that need it. */
+ if (cti->id_looper && (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
+ cti->id_looper(dst, con_fix_copied_refs_cb, NULL);
+ }
+
+ /* for proxies we don't want to make extern */
+ if (do_extern) {
+ /* go over used ID-links for this constraint to ensure that they are valid for proxies */
+ if (cti->id_looper)
+ cti->id_looper(dst, con_extern_cb, NULL);
+ }
+ }
+}
+
+/** Allocate and duplicate a single constraint, ouside of any object/pose context. */
+bConstraint *BKE_constraint_duplicate_ex(bConstraint *src, const int flag, const bool do_extern)
+{
+ bConstraint *dst = MEM_dupallocN(src);
+ constraint_copy_data_ex(dst, src, flag, do_extern);
+ dst->next = dst->prev = NULL;
+ return dst;
+}
+
/* duplicate all of the constraints in a constraint stack */
void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag, bool do_extern)
{
@@ -4666,29 +4703,7 @@ void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag,
BLI_duplicatelist(dst, src);
for (con = dst->first, srccon = src->first; con && srccon; srccon = srccon->next, con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
-
- /* make a new copy of the constraint's data */
- con->data = MEM_dupallocN(con->data);
-
- /* only do specific constraints if required */
- if (cti) {
- /* perform custom copying operations if needed */
- if (cti->copy_data)
- cti->copy_data(con, srccon);
-
- /* Fix usercounts for all referenced data that need it. */
- if (cti->id_looper && (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
- cti->id_looper(con, con_fix_copied_refs_cb, NULL);
- }
-
- /* for proxies we don't want to make extern */
- if (do_extern) {
- /* go over used ID-links for this constraint to ensure that they are valid for proxies */
- if (cti->id_looper)
- cti->id_looper(con, con_extern_cb, NULL);
- }
- }
+ constraint_copy_data_ex(con, srccon, flag, do_extern);
}
}