[Bf-blender-cvs] [4f18ab1] master: Fix T40958 align rotation + project individual elements not working

Antony Riakiotakis noreply at git.blender.org
Thu Jul 31 17:02:30 CEST 2014


Commit: 4f18ab1b20d497da5ea4b613b9ab9e9bc57d3761
Author: Antony Riakiotakis
Date:   Thu Jul 31 17:02:03 2014 +0200
Branches: master
https://developer.blender.org/rB4f18ab1b20d497da5ea4b613b9ab9e9bc57d3761

Fix T40958 align rotation + project individual elements not working

This is another example of transform code crappiness. Projection
snapping for objects is handled separately than regular snapping.
Luckilly for us, we have the normal ready from the raycast result and a
copy of code from ElementRotation function can do the necessary
rotations for us.

I have not enforced constraints here (arguably, maybe I should, and the
already present projection snapping should do that too but seems it is
commented out and the unorthodox order of operations here has me a bit
scared. Leaving as TODO)

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

M	source/blender/editors/transform/transform_snap.c

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

diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index dfb75bb..307f30f 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -337,6 +337,46 @@ void applyProject(TransInfo *t)
 					mul_m3_v3(td->smtx, tvec);
 
 					add_v3_v3(td->loc, tvec);
+
+					if (t->tsnap.align) {
+						/* handle alignment as well */
+						const float *original_normal;
+						float axis[3];
+						float mat[3][3];
+						float angle;
+						float totmat[3][3], smat[3][3];
+						float eul[3], fmat[3][3], quat[4];
+						float obmat[3][3];
+
+						/* In pose mode, we want to align normals with Y axis of bones... */
+						original_normal = td->axismtx[2];
+
+						cross_v3_v3v3(axis, original_normal, no);
+						angle = saacos(dot_v3v3(original_normal, no));
+
+						axis_angle_to_quat(quat, axis, angle);
+
+						quat_to_mat3(mat, quat);
+
+						mul_m3_m3m3(totmat, mat, td->mtx);
+						mul_m3_m3m3(smat, td->smtx, totmat);
+
+						/* calculate the total rotatation in eulers */
+						add_v3_v3v3(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
+						eulO_to_mat3(obmat, eul, td->ext->rotOrder);
+						/* mat = transform, obmat = object rotation */
+						mul_m3_m3m3(fmat, smat, obmat);
+
+						mat3_to_compatible_eulO(eul, td->ext->rot, td->ext->rotOrder, fmat);
+
+						/* correct back for delta rot */
+						sub_v3_v3v3(eul, eul, td->ext->drot);
+
+						/* and apply */
+						copy_v3_v3(td->ext->rot, eul);
+
+						/* TODO support constraints for rotation too? see ElementRotation */
+					}
 				}
 			}




More information about the Bf-blender-cvs mailing list