From de6064eab174ab29e0845b4d024825e72805ed01 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 27 Jun 2016 15:42:06 +1200 Subject: Ctrl-Shift-C: Made it easier to add constraints between bones in different armatures The Ctrl-Shift-C operator to add constraints between a pair of selected items, for example, between two objects, or between two bones (in the same armature). This commit makes it possible to use this operator to add a constraint where the target is a bone from another object - e.g. to make a deform bone follow the control bone in another armature, or to make an object use a bone as a tracking target. Usage: 1) Ensure you are in Pose Mode, then select the bone to use as the target 2) Shift-Select the other object and/or the bone that's going to get the constraint 3) Ctrl-Shift-C --- source/blender/editors/object/object_constraint.c | 44 +++++++++++++++-------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'source/blender/editors/object/object_constraint.c') diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index efd1ebbd51b..2b20d31c60f 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -1636,22 +1636,36 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o /* just use the first object we encounter (that isn't the active object) * and which fulfills the criteria for the object-target that we've got */ - if ((ob != obact) && - ((!only_curve) || (ob->type == OB_CURVE)) && - ((!only_mesh) || (ob->type == OB_MESH))) - { - /* set target */ - *tar_ob = ob; - found = 1; - - /* perform some special operations on the target */ - if (only_curve) { - /* Curve-Path option must be enabled for follow-path constraints to be able to work */ - Curve *cu = (Curve *)ob->data; - cu->flag |= CU_PATH; + if (ob != obact) { + /* for armatures in pose mode, look inside the armature for the active bone + * so that we set up cross-armature constraints with less effort + */ + if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) && + (!only_curve && !only_mesh)) + { + /* just use the active bone, and assume that it is visible + usable */ + *tar_ob = ob; + *tar_pchan = BKE_pose_channel_active(ob); + found = 1; + + break; + } + else if (((!only_curve) || (ob->type == OB_CURVE)) && + ((!only_mesh) || (ob->type == OB_MESH))) + { + /* set target */ + *tar_ob = ob; + found = 1; + + /* perform some special operations on the target */ + if (only_curve) { + /* Curve-Path option must be enabled for follow-path constraints to be able to work */ + Curve *cu = (Curve *)ob->data; + cu->flag |= CU_PATH; + } + + break; } - - break; } } CTX_DATA_END; -- cgit v1.2.3