From d2dc4f84115c52af15e643a1f82c042025ff1344 Mon Sep 17 00:00:00 2001 From: mano-wii Date: Fri, 27 Dec 2019 09:51:37 -0300 Subject: Transform: Use parent bone orientation if the bone has not size As shown in the T68805, non-sized bones (such as the resulting extruded bone) have no direction or orientation. This can be bad for operators like `extrude_move` since the user might want the resulting bone to be aligned with the bone that originated it. The solution here is to get the parent bone orientation in the transform operator if the bone has no size. Differential Revision: https://developer.blender.org/D6486 --- source/blender/editors/armature/armature_utils.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/armature/armature_utils.c') diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 2b18fc15f63..451148ed936 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -232,11 +232,22 @@ EditBone *ED_armature_ebone_find_shared_parent(EditBone *ebone_child[], void ED_armature_ebone_to_mat3(EditBone *ebone, float mat[3][3]) { - float delta[3]; + float delta[3], roll; /* Find the current bone matrix */ sub_v3_v3v3(delta, ebone->tail, ebone->head); - vec_roll_to_mat3(delta, ebone->roll, mat); + roll = ebone->roll; + if (!normalize_v3(delta)) { + /* Use the orientation of the parent bone if any. */ + const EditBone *ebone_parent = ebone->parent; + if (ebone_parent) { + sub_v3_v3v3(delta, ebone_parent->tail, ebone_parent->head); + normalize_v3(delta); + roll = ebone_parent->roll; + } + } + + vec_roll_to_mat3_normalized(delta, roll, mat); } void ED_armature_ebone_to_mat4(EditBone *ebone, float mat[4][4]) -- cgit v1.2.3