diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/armature/armature_edit.c | 10 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_relations.c | 9 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_utils.c | 27 | ||||
-rw-r--r-- | source/blender/editors/include/ED_armature.h | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawarmature.c | 16 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 11 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 53 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_armature.c | 11 |
8 files changed, 63 insertions, 78 deletions
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index 12602c10955..90c1a439a19 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -78,11 +78,10 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4]) /* Do the rotations */ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { - float delta[3], tmat[3][3]; + float tmat[3][3]; /* find the current bone's roll matrix */ - sub_v3_v3v3(delta, ebone->tail, ebone->head); - vec_roll_to_mat3(delta, ebone->roll, tmat); + ED_armature_ebone_to_mat3(ebone, tmat); /* transform the roll matrix */ mul_m3_m3m3(tmat, mat3, tmat); @@ -282,15 +281,14 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op) mul_m3_v3(imat, vec); } else if (type == CALC_ROLL_ACTIVE) { - float mat[3][3], nor[3]; + float mat[3][3]; ebone = (EditBone *)arm->act_edbone; if (ebone == NULL) { BKE_report(op->reports, RPT_ERROR, "No active bone set"); return OPERATOR_CANCELLED; } - sub_v3_v3v3(nor, ebone->tail, ebone->head); - vec_roll_to_mat3(nor, ebone->roll, mat); + ED_armature_ebone_to_mat3(ebone, mat); copy_v3_v3(vec, mat[2]); } else { /* Axis */ diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index 289901076a1..79d75c9fcda 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -242,21 +242,18 @@ int join_armature_exec(bContext *C, wmOperator *op) float difmat[4][4]; float imat[4][4]; float temp[3][3]; - float delta[3]; /* Get the premat */ - sub_v3_v3v3(delta, curbone->tail, curbone->head); - vec_roll_to_mat3(delta, curbone->roll, temp); + ED_armature_ebone_to_mat3(curbone, temp); - unit_m4(premat); /* Mat4MulMat34 only sets 3x3 part */ + unit_m4(premat); /* mul_m4_m3m4 only sets 3x3 part */ mul_m4_m3m4(premat, temp, mat); mul_m4_v3(mat, curbone->head); mul_m4_v3(mat, curbone->tail); /* Get the postmat */ - sub_v3_v3v3(delta, curbone->tail, curbone->head); - vec_roll_to_mat3(delta, curbone->roll, temp); + ED_armature_ebone_to_mat3(curbone, temp); copy_m4_m3(postmat, temp); /* Find the roll */ diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 0e93a00b01d..4991ef63cf5 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -156,6 +156,25 @@ bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebon return false; } +void ED_armature_ebone_to_mat3(EditBone *ebone, float mat[3][3]) +{ + float delta[3]; + + /* Find the current bone matrix */ + sub_v3_v3v3(delta, ebone->tail, ebone->head); + vec_roll_to_mat3(delta, ebone->roll, mat); +} + +void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4]) +{ + float m3[3][3]; + + ED_armature_ebone_to_mat3(ebone, m3); + + copy_m4_m3(mat, m3); + copy_v3_v3(mat[3], ebone->head); +} + /* *************************************************************** */ /* Mirroring */ @@ -389,7 +408,6 @@ static void fix_bonelist_roll(ListBase *bonelist, ListBase *editbonelist) float postmat[3][3]; float difmat[3][3]; float imat[3][3]; - float delta[3]; for (curBone = bonelist->first; curBone; curBone = curBone->next) { /* sets local matrix and arm_mat (restpos) */ @@ -402,8 +420,7 @@ static void fix_bonelist_roll(ListBase *bonelist, ListBase *editbonelist) if (ebone) { /* Get the ebone premat */ - sub_v3_v3v3(delta, ebone->tail, ebone->head); - vec_roll_to_mat3(delta, ebone->roll, premat); + ED_armature_ebone_to_mat3(ebone, premat); /* Get the bone postmat */ copy_m3_m4(postmat, curBone->arm_mat); @@ -503,11 +520,9 @@ void ED_armature_from_edit(Object *obedit) { float M_parentRest[3][3]; float iM_parentRest[3][3]; - float delta[3]; /* Get the parent's matrix (rotation only) */ - sub_v3_v3v3(delta, eBone->parent->tail, eBone->parent->head); - vec_roll_to_mat3(delta, eBone->parent->roll, M_parentRest); + ED_armature_ebone_to_mat3(eBone->parent, M_parentRest); /* Invert the parent matrix */ invert_m3_m3(iM_parentRest, M_parentRest); diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 9b9a4c154db..fab179da7bc 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -135,8 +135,12 @@ void ED_armature_validate_active(struct bArmature *arm); void add_primitive_bone(struct Object *obedit_arm, bool view_aligned); struct EditBone *ED_armature_edit_bone_add(struct bArmature *arm, const char *name); void ED_armature_edit_bone_remove(struct bArmature *arm, EditBone *exBone); + bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child); +void ED_armature_ebone_to_mat3(EditBone *ebone, float mat[3][3]); +void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4]); + void transform_armature_mirror_update(struct Object *obedit); void ED_armature_origin_set(struct Scene *scene, struct Object *ob, float cursor[3], int centermode, int around); diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index fb20f082085..68f656bbf57 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -2060,20 +2060,10 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, } /* in editmode, we don't store the bone matrix... */ -static void get_matrix_editbone(EditBone *eBone, float bmat[4][4]) +static void get_matrix_editbone(EditBone *ebone, float bmat[4][4]) { - float delta[3]; - float mat[3][3]; - - /* Compose the parent transforms (i.e. their translations) */ - sub_v3_v3v3(delta, eBone->tail, eBone->head); - - eBone->length = (float)sqrt(delta[0] * delta[0] + delta[1] * delta[1] + delta[2] * delta[2]); - - vec_roll_to_mat3(delta, eBone->roll, mat); - copy_m4_m3(bmat, mat); - - add_v3_v3(bmat[3], eBone->head); + ebone->length = len_v3v3(ebone->tail, ebone->head); + ED_armature_ebone_to_mat4(ebone, bmat); } static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt) diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 0a8687339a5..e44b9620b6f 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -1047,7 +1047,7 @@ static void createTransArmatureVerts(TransInfo *t) bArmature *arm = t->obedit->data; ListBase *edbo = arm->edbo; TransData *td; - float mtx[3][3], smtx[3][3], delta[3], bonemat[3][3]; + float mtx[3][3], smtx[3][3], bonemat[3][3]; /* special hack for envelope drawmode and scaling: * to allow scaling the size of the envelope around single points, @@ -1139,8 +1139,7 @@ static void createTransArmatureVerts(TransInfo *t) td->flag = TD_SELECTED; /* use local bone matrix */ - sub_v3_v3v3(delta, ebo->tail, ebo->head); - vec_roll_to_mat3(delta, ebo->roll, bonemat); + ED_armature_ebone_to_mat3(ebo, bonemat); mul_m3_m3m3(td->mtx, mtx, bonemat); invert_m3_m3(td->smtx, td->mtx); @@ -1180,8 +1179,7 @@ static void createTransArmatureVerts(TransInfo *t) copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); - sub_v3_v3v3(delta, ebo->tail, ebo->head); - vec_roll_to_mat3(delta, ebo->roll, td->axismtx); + ED_armature_ebone_to_mat3(ebo, td->axismtx); if ((ebo->flag & BONE_ROOTSEL) == 0) { td->extra = ebo; @@ -1204,8 +1202,7 @@ static void createTransArmatureVerts(TransInfo *t) copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); - sub_v3_v3v3(delta, ebo->tail, ebo->head); - vec_roll_to_mat3(delta, ebo->roll, td->axismtx); + ED_armature_ebone_to_mat3(ebo, td->axismtx); td->extra = ebo; /* to fix roll */ diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index a424613d616..55d80d63234 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -256,13 +256,19 @@ bool createSpaceNormal(float mat[3][3], const float normal[3]) return true; } +/** + * \note To recreate an orientation from the matrix: + * - (plane == mat[1]) + * - (normal == mat[2]) + */ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const float tangent[3]) { if (normalize_v3_v3(mat[2], normal) == 0.0f) { return false; /* error return */ } - copy_v3_v3(mat[1], tangent); + /* negate so we can use values from the matrix as input */ + negate_v3_v3(mat[1], tangent); /* preempt zero length tangent from causing trouble */ if (is_zero_v3(mat[1])) { mat[1][2] = 1.0f; @@ -691,6 +697,10 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], result = ORIENTATION_VERT; } } + + /* not needed but this matches 2.68 and older behavior */ + negate_v3(plane); + } /* end editmesh */ else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { Curve *cu = obedit->data; @@ -773,7 +783,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], copy_v3_v3(normal, qmat[2]); - negate_v3_v3(plane, qmat[1]); + copy_v3_v3(plane, qmat[1]); result = ORIENTATION_FACE; } @@ -781,45 +791,33 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], else if (obedit->type == OB_ARMATURE) { bArmature *arm = obedit->data; EditBone *ebone; - int ok = FALSE; - - /* grr. but better then duplicate code */ -#define EBONE_CALC_NORMAL_PLANE { \ - float tmat[3][3]; \ - float vec[3]; \ - sub_v3_v3v3(vec, ebone->tail, ebone->head); \ - normalize_v3(vec); \ - add_v3_v3(normal, vec); \ - \ - vec_roll_to_mat3(vec, ebone->roll, tmat); \ - add_v3_v3(plane, tmat[2]); \ - } (void)0 - + bool ok = false; + float tmat[3][3]; if (activeOnly && (ebone = arm->act_edbone)) { - EBONE_CALC_NORMAL_PLANE; - ok = TRUE; + ED_armature_ebone_to_mat3(ebone, tmat); + add_v3_v3(normal, tmat[2]); + add_v3_v3(plane, tmat[1]); + ok = true; } else { for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { if (arm->layer & ebone->layer) { if (ebone->flag & BONE_SELECTED) { - EBONE_CALC_NORMAL_PLANE; - ok = TRUE; + ED_armature_ebone_to_mat3(ebone, tmat); + add_v3_v3(normal, tmat[2]); + add_v3_v3(plane, tmat[1]); + ok = true; } } } } if (ok) { - normalize_v3(normal); - normalize_v3(plane); - if (!is_zero_v3(plane)) { result = ORIENTATION_EDGE; } } -#undef EBONE_CALC_NORMAL_PLANE } /* Vectors from edges don't need the special transpose inverse multiplication */ @@ -861,8 +859,6 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], /* use for both active & all */ if (ok) { - negate_v3(plane); - /* we need the transpose of the inverse for a normal... */ copy_m3_m4(imat, ob->obmat); @@ -895,11 +891,8 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], } if (ob) { - /* note: negating the plane so when used with createSpaceNormalTangent(), - * we want the normal and the plane to make the same orientation as - * what we would get from 'ob->obmat' */ copy_v3_v3(normal, ob->obmat[2]); - negate_v3_v3(plane, ob->obmat[1]); + copy_v3_v3(plane, ob->obmat[1]); } result = ORIENTATION_NORMAL; } diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index fd151ccebb9..a832a8cdf96 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -398,16 +398,7 @@ static void rna_EditBone_parent_set(PointerRNA *ptr, PointerRNA value) static void rna_EditBone_matrix_get(PointerRNA *ptr, float *values) { EditBone *ebone = (EditBone *)(ptr->data); - - float delta[3], tmat[3][3], mat[4][4]; - - /* Find the current bone matrix */ - sub_v3_v3v3(delta, ebone->tail, ebone->head); - vec_roll_to_mat3(delta, ebone->roll, tmat); - copy_m4_m3(mat, tmat); - copy_v3_v3(mat[3], ebone->head); - - memcpy(values, mat, 16 * sizeof(float)); + ED_armature_ebone_to_mat4(ebone, (float(*)[4])values); } static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr) |