diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/armature/armature_utils.c | 25 | ||||
-rw-r--r-- | source/blender/editors/include/ED_armature.h | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 52e3285d240..f22e668bcb7 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -216,6 +216,31 @@ void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4]) copy_v3_v3(mat[3], ebone->head); } +void ED_armature_ebone_from_mat3(EditBone *ebone, float mat[3][3]) +{ + float vec[3], roll; + const float len = len_v3v3(ebone->head, ebone->tail); + + mat3_to_vec_roll(mat, vec, &roll); + + madd_v3_v3v3fl(ebone->tail, ebone->head, vec, len); + ebone->roll = roll; +} + +void ED_armature_ebone_from_mat4(EditBone *ebone, float mat[4][4]) +{ + float mat3[3][3]; + + copy_m3_m4(mat3, mat); + /* We want normalized matrix here, to be consistent with ebone_to_mat. */ + BLI_ASSERT_UNIT_M3(mat3); + + sub_v3_v3(ebone->tail, ebone->head); + copy_v3_v3(ebone->head, mat[3]); + add_v3_v3(ebone->tail, mat[3]); + ED_armature_ebone_from_mat3(ebone, mat3); +} + /** * Return a pointer to the bone of the given name */ diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index be2c7daac85..7579f6cba65 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -143,6 +143,9 @@ EditBone *ED_armature_bone_find_shared_parent(EditBone *ebone_child[], const uns 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 ED_armature_ebone_from_mat3(EditBone *ebone, float mat[3][3]); +void ED_armature_ebone_from_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); |