Revision: 42491
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42491
Author: mont29
Date: 2011-12-07 15:55:37 +0000 (Wed, 07 Dec 2011)
Log Message:
-----------
More fix for snapto in Pose mode:
* The code for snap to grid was completely wrong (only x pos of chan was
affected?\226?\128?\166 by z computed value!), and the same problem as with
snap to cursor was present (using armature_loc_pose_to_bone is wrong here).
Also, computing nearest grid point in world space! Else, it generally ends up
completely out of grid, due to object transforms...
* Small cleanup of code (uneeded vars and copying).
Modified Paths:
--------------
trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
2011-12-07 15:21:38 UTC (rev 42490)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_snap.c
2011-12-07 15:55:37 UTC (rev 42491)
@@ -501,28 +501,36 @@
bPoseChannel *pchan;
bArmature *arm= ob->data;
+ invert_m4_m4(ob->imat, ob->obmat);
+
for (pchan= ob->pose->chanbase.first; pchan;
pchan= pchan->next) {
if(pchan->bone->flag & BONE_SELECTED) {
if(pchan->bone->layer &
arm->layer) {
if((pchan->bone->flag &
BONE_CONNECTED)==0) {
- float vecN[3],
nLoc[3];
+ float nLoc[3];
+ float
inv_restmat[4][4];
/* get nearest
grid point to snap to */
copy_v3_v3(nLoc, pchan->pose_mat[3]);
+ /* We must
operate in world space! */
+
mul_m4_v3(ob->obmat, nLoc);
vec[0]= gridf *
(float)(floor(0.5f+ nLoc[0]/gridf));
vec[1]= gridf *
(float)(floor(0.5f+ nLoc[1]/gridf));
vec[2]= gridf *
(float)(floor(0.5f+ nLoc[2]/gridf));
+ /* Back in
object space... */
+
mul_m4_v3(ob->imat, vec);
- /* get
bone-space location of grid point */
-
armature_loc_pose_to_bone(pchan, vec, vecN);
+ /* get location
of cursor in *rest* bone-space */
+
invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
+
mul_m4_v3(inv_restmat, vec);
/* adjust
location */
if
((pchan->protectflag & OB_LOCK_LOCX)==0)
-
pchan->loc[0]= vecN[0];
+
pchan->loc[0]= vec[0];
if
((pchan->protectflag & OB_LOCK_LOCY)==0)
-
pchan->loc[0]= vecN[1];
+
pchan->loc[1]= vec[1];
if
((pchan->protectflag & OB_LOCK_LOCZ)==0)
-
pchan->loc[0]= vecN[2];
+
pchan->loc[2]= vec[2];
/*
auto-keyframing */
ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
@@ -630,31 +638,28 @@
if(ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan;
bArmature *arm= ob->data;
- float cursp[3];
invert_m4_m4(ob->imat, ob->obmat);
- copy_v3_v3(cursp, curs);
- mul_m4_v3(ob->imat, cursp);
+ copy_v3_v3(vec, curs);
+ mul_m4_v3(ob->imat, vec);
for (pchan = ob->pose->chanbase.first; pchan;
pchan=pchan->next) {
if(pchan->bone->flag & BONE_SELECTED) {
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 *rest* bone-space */
-
copy_v3_v3(curspn, cursp);
invert_m4_m4(inv_restmat, pchan->bone->arm_mat);
-
mul_m4_v3(inv_restmat, curspn);
+
mul_m4_v3(inv_restmat, vec);
/* copy new
position */
if
((pchan->protectflag & OB_LOCK_LOCX)==0)
-
pchan->loc[0]= curspn[0];
+
pchan->loc[0]= vec[0];
if
((pchan->protectflag & OB_LOCK_LOCY)==0)
-
pchan->loc[1]= curspn[1];
+
pchan->loc[1]= vec[1];
if
((pchan->protectflag & OB_LOCK_LOCZ)==0)
-
pchan->loc[2]= curspn[2];
+
pchan->loc[2]= vec[2];
/*
auto-keyframing */
ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs
