diff options
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index c5b70cf6924..74e3cc567ec 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -5448,18 +5448,11 @@ static bConstraint *add_new_constraint_internal(const char *name, short type) return con; } -/* if pchan is not NULL then assume we're adding a pose constraint */ -static bConstraint *add_new_constraint(Object *ob, - bPoseChannel *pchan, - const char *name, - short type) +/* Add a newly created constraint to the constraint list. */ +static void add_new_constraint_to_list(Object *ob, bPoseChannel *pchan, bConstraint *con) { - bConstraint *con; ListBase *list; - /* add the constraint */ - con = add_new_constraint_internal(name, type); - /* find the constraint stack - bone or object? */ list = (pchan) ? (&pchan->constraints) : (&ob->constraints); @@ -5481,6 +5474,20 @@ static bConstraint *add_new_constraint(Object *ob, /* make this constraint the active one */ BKE_constraints_active_set(list, con); } +} + +/* if pchan is not NULL then assume we're adding a pose constraint */ +static bConstraint *add_new_constraint(Object *ob, + bPoseChannel *pchan, + const char *name, + short type) +{ + bConstraint *con; + + /* add the constraint */ + con = add_new_constraint_internal(name, type); + + add_new_constraint_to_list(ob, pchan, con); /* set type+owner specific immutable settings */ /* TODO: does action constraint need anything here - i.e. spaceonce? */ @@ -5614,6 +5621,26 @@ bConstraint *BKE_constraint_duplicate_ex(bConstraint *src, const int flag, const return dst; } +/* Add a copy of the given constraint for the given bone */ +bConstraint *BKE_constraint_copy_for_pose(Object *ob, bPoseChannel *pchan, bConstraint *src) +{ + if (pchan == NULL) { + return NULL; + } + + bConstraint *new_con = BKE_constraint_duplicate_ex(src, 0, !ID_IS_LINKED(ob)); + add_new_constraint_to_list(ob, pchan, new_con); + return new_con; +} + +/* Add a copy of the given constraint for the given object */ +bConstraint *BKE_constraint_copy_for_object(Object *ob, bConstraint *src) +{ + bConstraint *new_con = BKE_constraint_duplicate_ex(src, 0, !ID_IS_LINKED(ob)); + add_new_constraint_to_list(ob, NULL, new_con); + return new_con; +} + /* 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) { |