diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-01 06:15:44 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-01 06:17:10 +0300 |
commit | 5915d1f453e94c722cd1bfea45cbce0bf436309d (patch) | |
tree | 2f00ad3578bb342b1ba8de3e899c584875e2337b | |
parent | 340c564020f580579e2d7db63ba860527cd72ea3 (diff) |
BKE_pchan: add BKE_pchan_rot_to_mat3
Useful to get the un-scaled rotation from a pose channel.
-rw-r--r-- | source/blender/blenkernel/BKE_armature.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 51 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 2 |
4 files changed, 34 insertions, 24 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 267617e154f..b5da30e725d 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -144,8 +144,9 @@ void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, float outmat[4][4]); void BKE_pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[3][3], bool use_compat); +void BKE_pchan_rot_to_mat3(const struct bPoseChannel *pchan, float mat[3][3]); void BKE_pchan_apply_mat4(struct bPoseChannel *pchan, float mat[4][4], bool use_comat); -void BKE_pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]); +void BKE_pchan_to_mat4(const struct bPoseChannel *pchan, float chan_mat[4][4]); void BKE_pchan_calc_mat(struct bPoseChannel *pchan); /* Simple helper, computes the offset bone matrix. */ diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index ab7ca44368c..49b35bfccc1 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -153,7 +153,7 @@ struct Object *BKE_object_duplicate(struct Main *bmain, void BKE_object_obdata_size_init(struct Object *ob, const float scale); void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]); -void BKE_object_rot_to_mat3(struct Object *ob, float mat[3][3], bool use_drot); +void BKE_object_rot_to_mat3(const struct Object *ob, float mat[3][3], bool use_drot); void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat); void BKE_object_to_mat3(struct Object *ob, float mat[3][3]); void BKE_object_to_mat4(struct Object *ob, float mat[4][4]); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 7f374c1d66e..9645721d29b 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1873,6 +1873,33 @@ void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, float mat[3][3], bool use_compat } /** + * Same as #BKE_object_rot_to_mat3(). + */ +void BKE_pchan_rot_to_mat3(const bPoseChannel *pchan, float mat[3][3]) +{ + /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ + if (pchan->rotmode > 0) { + /* euler rotations (will cause gimble lock, + * but this can be alleviated a bit with rotation orders) */ + eulO_to_mat3(mat, pchan->eul, pchan->rotmode); + } + else if (pchan->rotmode == ROT_MODE_AXISANGLE) { + /* axis-angle - not really that great for 3D-changing orientations */ + axis_angle_to_mat3(mat, pchan->rotAxis, pchan->rotAngle); + } + else { + /* quats are normalized before use to eliminate scaling issues */ + float quat[4]; + + /* NOTE: we now don't normalize the stored values anymore, + * since this was kindof evil in some cases but if this proves to be too problematic, + * switch back to the old system of operating directly on the stored copy. */ + normalize_qt_qt(quat, pchan->quat); + quat_to_mat3(mat, quat); + } +} + +/** * Apply a 4x4 matrix to the pose bone, * similar to #BKE_object_apply_mat4(). */ @@ -2468,7 +2495,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ /* ********************** THE POSE SOLVER ******************* */ /* loc/rot/size to given mat4 */ -void BKE_pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) +void BKE_pchan_to_mat4(const bPoseChannel *pchan, float chan_mat[4][4]) { float smat[3][3]; float rmat[3][3]; @@ -2477,26 +2504,8 @@ void BKE_pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) /* get scaling matrix */ size_to_mat3(smat, pchan->size); - /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ - if (pchan->rotmode > 0) { - /* euler rotations (will cause gimble lock, - * but this can be alleviated a bit with rotation orders) */ - eulO_to_mat3(rmat, pchan->eul, pchan->rotmode); - } - else if (pchan->rotmode == ROT_MODE_AXISANGLE) { - /* axis-angle - not really that great for 3D-changing orientations */ - axis_angle_to_mat3(rmat, pchan->rotAxis, pchan->rotAngle); - } - else { - /* quats are normalized before use to eliminate scaling issues */ - float quat[4]; - - /* NOTE: we now don't normalize the stored values anymore, - * since this was kindof evil in some cases but if this proves to be too problematic, - * switch back to the old system of operating directly on the stored copy. */ - normalize_qt_qt(quat, pchan->quat); - quat_to_mat3(rmat, quat); - } + /* get rotation matrix */ + BKE_pchan_rot_to_mat3(pchan, rmat); /* calculate matrix of bone (as 3x3 matrix, but then copy the 4x4) */ mul_m3_m3m3(tmat, rmat, smat); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 35e25086924..38a8ad2769a 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2016,7 +2016,7 @@ void BKE_object_scale_to_mat3(Object *ob, float mat[3][3]) size_to_mat3(mat, vec); } -void BKE_object_rot_to_mat3(Object *ob, float mat[3][3], bool use_drot) +void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot) { float rmat[3][3], dmat[3][3]; |