diff options
author | Joshua Leung <aligorith@gmail.com> | 2007-03-24 06:00:54 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2007-03-24 06:00:54 +0300 |
commit | 269e943d5849ff1f9f897f6ac32f6a64a1168afe (patch) | |
tree | 64a24ce87ae035164b19e82a623d9709d6bd13be /source | |
parent | 26fd086bca9aad6ea1b44813d8e52446d1b9e25b (diff) |
== Copy Location Constraint ==
I've added two new options for this constraint:
* Copy Bone Tip Location
* Apply owner's location on top of copied location ('Offset')
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 41 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 46 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_constraint_types.h | 12 | ||||
-rw-r--r-- | source/blender/src/buttons_object.c | 21 |
4 files changed, 87 insertions, 33 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 9c764f58315..2b09f19eac1 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1614,12 +1614,31 @@ static void do_local_constraint(bPoseChannel *pchan, bConstraint *con) if(data->tar && data->subtarget[0]) { bPoseChannel *pchant= get_pose_channel(data->tar->pose, data->subtarget); if(pchant) { + float loc[3]; + + /* copy location of tip of bone? */ + if (data->flag & LOCLIKE_TIP) { + float mat[4][4], tmat[4][4]; + + Mat4One(tmat); + VECCOPY(tmat[3], pchant->pose_tail); + + armature_mat_pose_to_delta(mat, tmat, pchant->bone->arm_mat); + VECCOPY(loc, mat[3]); + } + else + VECCOPY(loc, pchant->loc); + + /* do offsets? */ + if (data->flag & LOCLIKE_OFFSET) + VecAddf(loc, loc, pchan->loc); + if (data->flag & LOCLIKE_X) - pchan->loc[0]= FloatLerpf(pchant->loc[0], pchan->loc[0], fac); + pchan->loc[0]= FloatLerpf(loc[0], pchan->loc[0], fac); if (data->flag & LOCLIKE_Y) - pchan->loc[1]= FloatLerpf(pchant->loc[1], pchan->loc[1], fac); + pchan->loc[1]= FloatLerpf(loc[1], pchan->loc[1], fac); if (data->flag & LOCLIKE_Z) - pchan->loc[2]= FloatLerpf(pchant->loc[2], pchan->loc[2], fac); + pchan->loc[2]= FloatLerpf(loc[2], pchan->loc[2], fac); if (data->flag & LOCLIKE_X_INVERT) pchan->loc[0]= FloatLerpf(pchant->loc[0], pchan->loc[0], -fac); if (data->flag & LOCLIKE_Y_INVERT) @@ -1637,17 +1656,20 @@ static void do_local_constraint(bPoseChannel *pchan, bConstraint *con) bPoseChannel *pchant= get_pose_channel(data->tar->pose, data->subtarget); if(pchant) { if(data->flag != (ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z)) { - float eul[3], eult[3], euln[3], fac= con->enforce; + float eul[3], eult[3], euln[3]; + float fac= con->enforce; QuatToEul(pchan->quat, eul); QuatToEul(pchant->quat, eult); VECCOPY(euln, eul); + if(data->flag & ROTLIKE_X) euln[0]= FloatLerpf(eult[0], eul[0], fac); if(data->flag & ROTLIKE_Y) euln[1]= FloatLerpf(eult[1], eul[1], fac); if(data->flag & ROTLIKE_Z) euln[2]= FloatLerpf(eult[2], eul[2], fac); if(data->flag & ROTLIKE_X_INVERT) euln[0]= FloatLerpf(eult[0], eul[0], -fac); if(data->flag & ROTLIKE_Y_INVERT) euln[1]= FloatLerpf(eult[1], eul[1], -fac); if(data->flag & ROTLIKE_Z_INVERT) euln[2]= FloatLerpf(eult[2], eul[2], -fac); + compatible_eul(eul, euln); EulToQuat(euln, pchan->quat); } @@ -1800,7 +1822,9 @@ static void do_strip_modifiers(Object *armob, Bone *bone, bPoseChannel *pchan) continue; for(amod= strip->modifiers.first; amod; amod= amod->next) { - if(amod->type==ACTSTRIP_MOD_DEFORM) { + switch (amod->type) { + case ACTSTRIP_MOD_DEFORM: + { /* validate first */ if(amod->ob && amod->ob->type==OB_CURVE && amod->channel[0]) { @@ -1814,6 +1838,13 @@ static void do_strip_modifiers(Object *armob, Bone *bone, bPoseChannel *pchan) } } } + break; + case ACTSTRIP_MOD_NOISE: + { + + } + break; + } } } } diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 19bd843edbe..890a292b99a 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -1063,9 +1063,32 @@ short get_constraint_target_matrix (bConstraint *con, short ownertype, void* own case CONSTRAINT_TYPE_LOCLIKE: { bLocateLikeConstraint *data = (bLocateLikeConstraint*)con->data; - - if (data->tar){ - constraint_target_to_mat4(data->tar, data->subtarget, mat, size); + Object *ob= data->tar; + + if (data->tar) { + if (strlen(data->subtarget)) { + bPoseChannel *pchan; + float tmat[4][4]; + float bsize[3]={1, 1, 1}; + + pchan = get_pose_channel(ob->pose, data->subtarget); + if (pchan) { + Mat4CpyMat4(tmat, pchan->pose_mat); + + if (data->flag & LOCLIKE_TIP) + VECCOPY(tmat[3], pchan->pose_tail); + + Mat4MulMat4 (mat, tmat, ob->obmat); + } + else + Mat4CpyMat4 (mat, ob->obmat); + + VECCOPY(size, bsize); // what's this hack for? + } + else { + Mat4CpyMat4 (mat, ob->obmat); + VECCOPY(size, data->tar->size); // what's this hack for? + } valid=1; } else @@ -1273,23 +1296,32 @@ void evaluate_constraint (bConstraint *constraint, Object *ob, short ownertype, case CONSTRAINT_TYPE_LOCLIKE: { bLocateLikeConstraint *data; + float offset[3] = {0.0f, 0.0f, 0.0f}; data = constraint->data; + if (data->flag & LOCLIKE_OFFSET) { + // for now... + VECCOPY(offset, ob->obmat[3]); + } + if (data->flag & LOCLIKE_X) { ob->obmat[3][0] = targetmat[3][0]; - if(data->flag & LOCLIKE_X_INVERT) ob->obmat[3][0] *= -1; + if(data->flag & LOCLIKE_X_INVERT) ob->obmat[3][0] *= -1; + ob->obmat[3][0] += offset[0]; } if (data->flag & LOCLIKE_Y) { ob->obmat[3][1] = targetmat[3][1]; if(data->flag & LOCLIKE_Y_INVERT) ob->obmat[3][1] *= -1; + ob->obmat[3][1] += offset[1]; } if (data->flag & LOCLIKE_Z) { ob->obmat[3][2] = targetmat[3][2]; if(data->flag & LOCLIKE_Z_INVERT) ob->obmat[3][2] *= -1; + ob->obmat[3][2] += offset[2]; } } break; @@ -1307,7 +1339,7 @@ void evaluate_constraint (bConstraint *constraint, Object *ob, short ownertype, Mat4ToEul(targetmat, eul); Mat4ToEul(ob->obmat, obeul); - + if(data->flag != (ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z)) { if(!(data->flag & ROTLIKE_X)) { eul[0]= obeul[0]; @@ -1320,14 +1352,14 @@ void evaluate_constraint (bConstraint *constraint, Object *ob, short ownertype, } compatible_eul(eul, obeul); } - + if((data->flag & ROTLIKE_X) && (data->flag & ROTLIKE_X_INVERT)) eul[0]*=-1; if((data->flag & ROTLIKE_Y) && (data->flag & ROTLIKE_Y_INVERT)) eul[1]*=-1; if((data->flag & ROTLIKE_Z) && (data->flag & ROTLIKE_Z_INVERT)) eul[2]*=-1; - + LocEulSizeToMat4(ob->obmat, loc, eul, size); } break; diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 0aa78a12a9f..14506f1b1aa 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -253,27 +253,29 @@ typedef struct bRigidBodyJointConstraint{ #define CONSTRAINT_CHANNEL_PROTECTED 0x02 /* bRotateLikeConstraint.flag */ -#define ROTLIKE_X 0x01 -#define ROTLIKE_Y 0x02 -#define ROTLIKE_Z 0x04 +#define ROTLIKE_X 0x01 +#define ROTLIKE_Y 0x02 +#define ROTLIKE_Z 0x04 #define ROTLIKE_X_INVERT 0x08 #define ROTLIKE_Y_INVERT 0x10 #define ROTLIKE_Z_INVERT 0x20 +#define ROTLIKE_OFFSET 0x40 /* bLocateLikeConstraint.flag */ #define LOCLIKE_X 0x01 #define LOCLIKE_Y 0x02 #define LOCLIKE_Z 0x04 -#define LOCSPACE 0x08 +#define LOCLIKE_TIP 0x08 #define LOCLIKE_X_INVERT 0x10 #define LOCLIKE_Y_INVERT 0x20 #define LOCLIKE_Z_INVERT 0x40 +#define LOCLIKE_OFFSET 0x80 /* bSizeLikeConstraint.flag */ #define SIZELIKE_X 0x01 #define SIZELIKE_Y 0x02 #define SIZELIKE_Z 0x04 -#define SIZESPACE 0x08 +#define SIZELIKE_OFFSET 0x08 /* Axis flags */ #define LOCK_X 0x00 diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index 2a93b02d98e..ec848b9896b 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -597,7 +597,7 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); uiButSetFunc(but, verify_constraint_name_func, con, NULL); } - else{ + else { uiBlockSetEmboss(block, UI_EMBOSSN); if (con->flag & CONSTRAINT_DISABLE) { @@ -734,6 +734,8 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s /* Draw XYZ toggles */ uiBlockBeginAlign(block); + if (is_armature_target) + uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+((width/2)-98), *yco-64, 50, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform"); but=uiDefButBitI(block, TOG, ROTLIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component"); but=uiDefButBitI(block, TOG, ROTLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component"); but=uiDefButBitI(block, TOG, ROTLIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component"); @@ -741,14 +743,6 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s but=uiDefButBitI(block, TOG, ROTLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component"); but=uiDefButBitI(block, TOG, ROTLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component"); uiBlockEndAlign(block); - - /* Draw options */ - if (is_armature_target) { - uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco, *yco-89, (width/2), 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform"); - uiDefButBitI(block, TOG, ROTLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco+(width/2), *yco-89, (width/2), 18, &data->flag, 0, 24, 0, 0, "Add original rotation onto copied rotation"); - } - else - uiDefButBitI(block, TOG, ROTLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco+(width/4), *yco-89, (width/2), 18, &data->flag, 0, 24, 0, 0, "Add original rotation onto copied rotation"); } break; case CONSTRAINT_TYPE_SIZELIKE: @@ -776,17 +770,12 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s /* Draw XYZ toggles */ uiBlockBeginAlign(block); + if (is_armature_target) + uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+((width/2)-98), *yco-64, 50, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform"); but=uiDefButBitI(block, TOG, SIZELIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component"); but=uiDefButBitI(block, TOG, SIZELIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component"); but=uiDefButBitI(block, TOG, SIZELIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component"); uiBlockEndAlign(block); - - if (is_armature_target) { - uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco, *yco-89, (width/2), 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform"); - uiDefButBitI(block, TOG, SIZELIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco+(width/2), *yco-89, (width/2), 18, &data->flag, 0, 24, 0, 0, "Add original scaling onto copied scale"); - } - else - uiDefButBitI(block, TOG, SIZELIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco+(width/4), *yco-89, (width/2), 18, &data->flag, 0, 24, 0, 0, "Add original scaling onto copied scale"); } break; case CONSTRAINT_TYPE_KINEMATIC: |