diff options
-rw-r--r-- | source/blender/ikplugin/intern/iksolver_plugin.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index b3c83bffb3f..30dd5e45a2b 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -50,6 +50,8 @@ #include <string.h> /* memcpy */ +#define USE_NONUNIFORM_SCALE + /* ********************** THE IK SOLVER ******************* */ /* allocates PoseTree, and links that to root bone/channel */ @@ -542,6 +544,19 @@ void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPose /* tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() */ tree->pchan[a]->flag |= POSE_CHAIN; } + +#ifdef USE_NONUNIFORM_SCALE + float (*pchan_scale_data)[3] = MEM_mallocN(sizeof(float[3]) * tree->totchannel, __func__); + + for (a = 0; a < tree->totchannel; a++) { + mat4_to_size(pchan_scale_data[a], tree->pchan[a]->pose_mat); + + /* make uniform at y scale since this controls the length */ + normalize_v3_length(tree->pchan[a]->pose_mat[0], pchan_scale_data[a][1]); + normalize_v3_length(tree->pchan[a]->pose_mat[2], pchan_scale_data[a][1]); + } +#endif + /* 5. execute the IK solver */ execute_posetree(scene, ob, tree); @@ -556,6 +571,14 @@ void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPose where_is_ik_bone(tree->pchan[a], tree->basis_change[a]); } +#ifdef USE_NONUNIFORM_SCALE + for (a = 0; a < tree->totchannel; a++) { + normalize_v3_length(pchan->pose_mat[0], pchan_scale_data[a][0]); + normalize_v3_length(pchan->pose_mat[2], pchan_scale_data[a][2]); + } + MEM_freeN(pchan_scale_data); +#endif + /* 7. and free */ BLI_remlink(&pchan->iktree, tree); free_posetree(tree); |