From e5ddaefecc1c6df3df15f22d6ce5609bb5c6cc3d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 26 Aug 2011 06:22:12 +0000 Subject: [PATCH] when applying armature object transform now transform the bone roll too. This means you can import a BVH, rotate 90d and apply the rotation, the animation will still work as expected - thanks to Benjy's script for showing how obvious it is that this works :) --- .../blender/editors/armature/editarmature.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index bd8f431535e..451154ce842 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -494,15 +494,32 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4]) EditBone *ebone; bArmature *arm= ob->data; float scale = mat4_to_scale(mat); /* store the scale of the matrix here to use on envelopes */ - + float mat3[3][3]; + + copy_m3_m4(mat3, mat); + normalize_m3(mat3); + /* Put the armature into editmode */ ED_armature_to_edit(ob); /* Do the rotations */ - for (ebone = arm->edbo->first; ebone; ebone=ebone->next){ + for (ebone = arm->edbo->first; ebone; ebone=ebone->next) { + float delta[3], 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); + + /* transform the roll matrix */ + mul_m3_m3m3(tmat, mat3, tmat); + + /* transform the bone */ mul_m4_v3(mat, ebone->head); mul_m4_v3(mat, ebone->tail); - + + /* apply the transfiormed roll back */ + mat3_to_vec_roll(tmat, delta, &ebone->roll); + ebone->rad_head *= scale; ebone->rad_tail *= scale; ebone->dist *= scale;