Fix [#29461] Selection-to-Cursor works strange with bones with TrackTo constraint.
authorBastien Montagne <montagne29@wanadoo.fr>
Wed, 7 Dec 2011 15:21:38 +0000 (15:21 +0000)
committerBastien Montagne <montagne29@wanadoo.fr>
Wed, 7 Dec 2011 15:21:38 +0000 (15:21 +0000)
In fact, the problem was present with any kind of constraint…

We need the cursor coordinates in the rest bone space (aka armature space), i.e with all "manual" and "procedural" (constraints, ...) pose transforms cleared (as said in armature_mat_pose_to_bone:

/* Remove the pchan's transforms from it's pose_mat.
 * This should leave behind the effects of restpose +
 * parenting + constraints
 */

, only "manual" transforms are "cleared" by armature_loc_pose_to_bone...).

source/blender/editors/space_view3d/view3d_snap.c

index b2707db806fec07653f902149a81d62f42167b1f..0b33ac0d3cd79baa62832f22215d0ce2e94edb4a 100644 (file)
@@ -641,16 +641,19 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
                                                if(pchan->bone->layer & arm->layer) {
                                                        if((pchan->bone->flag & BONE_CONNECTED)==0) { 
                                                                float curspn[3];
+                                                               float inv_restmat[4][4];
                                                                
-                                                               /* get location of cursor in bone-space */
-                                                               armature_loc_pose_to_bone(pchan, cursp, curspn);
+                                                               /* get location of cursor in *rest* bone-space */
+                                                               copy_v3_v3(curspn, cursp);
+                                                               invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
+                                                               mul_m4_v3(inv_restmat, curspn);
                                                                
                                                                /* copy new position */
-                                                               if ((pchan->protectflag & OB_LOCK_LOCX)==0)     
+                                                               if ((pchan->protectflag & OB_LOCK_LOCX)==0)
                                                                        pchan->loc[0]= curspn[0];
-                                                               if ((pchan->protectflag & OB_LOCK_LOCY)==0)     
+                                                               if ((pchan->protectflag & OB_LOCK_LOCY)==0)
                                                                        pchan->loc[1]= curspn[1];
-                                                               if ((pchan->protectflag & OB_LOCK_LOCZ)==0)     
+                                                               if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
                                                                        pchan->loc[2]= curspn[2];
 
                                                                /* auto-keyframing */