[Bf-blender-cvs] [a92fc34] master: Fix/Workaround non-uniform scaled bones failing w/ IK solver

Campbell Barton noreply at git.blender.org
Fri Jul 8 02:25:50 CEST 2016


Commit: a92fc348f46755c34023eff4fc1d7f467241c616
Author: Campbell Barton
Date:   Fri Jul 8 10:18:40 2016 +1000
Branches: master
https://developer.blender.org/rBa92fc348f46755c34023eff4fc1d7f467241c616

Fix/Workaround non-uniform scaled bones failing w/ IK solver

Scaling a bone on the Y axis (for a stretch effect), wasn't supported by the IK solver.

Support this by solving as uniform scaled bones by matching the X,Z axis to the Y.

Requested by @pepeland, see D2088 for details.

===================================================================

M	source/blender/ikplugin/intern/iksolver_plugin.c

===================================================================

diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c
index b3c83bf..30dd5e4 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);




More information about the Bf-blender-cvs mailing list