[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14129] trunk/blender/source/blender/src: Todo #8511: Lock Transform Channels does not work with Clear Transforms

Joshua Leung aligorith at gmail.com
Sun Mar 16 04:11:58 CET 2008


Revision: 14129
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14129
Author:   aligorith
Date:     2008-03-16 04:11:57 +0100 (Sun, 16 Mar 2008)

Log Message:
-----------
Todo #8511: Lock Transform Channels does not work with Clear Transforms

When transform channels (i.e. LocX, RotY, ScaleZ) are 'locked' in the Transform Properties panel, the Clear Transform Tools (Alt-G/R/S) didn't respect these.

Also fixed typo in 3D-View Menu item.

Modified Paths:
--------------
    trunk/blender/source/blender/src/editarmature.c
    trunk/blender/source/blender/src/editobject.c
    trunk/blender/source/blender/src/header_view3d.c

Modified: trunk/blender/source/blender/src/editarmature.c
===================================================================
--- trunk/blender/source/blender/src/editarmature.c	2008-03-16 01:31:14 UTC (rev 14128)
+++ trunk/blender/source/blender/src/editarmature.c	2008-03-16 03:11:57 UTC (rev 14129)
@@ -2843,23 +2843,56 @@
 	bPoseChannel *pchan;
 	bArmature	*arm;
 
-	arm=get_armature(ob);
-	
-	if (!arm)
+	arm= get_armature(ob);
+	if (arm == NULL)
 		return;
 	
-	for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-		if(pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
-			if(arm->layer & pchan->bone->layer) {
+	/* only clear those channels that are not locked */
+	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+		if (pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
+			if (arm->layer & pchan->bone->layer) {
 				switch (mode) {
 					case 'r':
-						pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F; pchan->quat[0]=1.0F;
+						if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
+							float eul[3], oldeul[3], quat1[4];
+							
+							QUATCOPY(quat1, pchan->quat);
+							QuatToEul(pchan->quat, oldeul);
+							eul[0]= eul[1]= eul[2]= 0.0f;
+							
+							if (pchan->protectflag & OB_LOCK_ROTX)
+								eul[0]= oldeul[0];
+							if (pchan->protectflag & OB_LOCK_ROTY)
+								eul[1]= oldeul[1];
+							if (pchan->protectflag & OB_LOCK_ROTZ)
+								eul[2]= oldeul[2];
+							
+							EulToQuat(eul, pchan->quat);
+							/* quaternions flip w sign to accumulate rotations correctly */
+							if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) {
+								QuatMulf(pchan->quat, -1.0f);
+							}
+						}						
+						else { 
+							pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F; 
+							pchan->quat[0]=1.0F;
+						}
 						break;
 					case 'g':
-						pchan->loc[0]=pchan->loc[1]=pchan->loc[2]=0.0F;
+						if ((pchan->protectflag & OB_LOCK_LOCX)==0)
+							pchan->loc[0]= 0.0f;
+						if ((pchan->protectflag & OB_LOCK_LOCY)==0)
+							pchan->loc[1]= 0.0f;
+						if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
+							pchan->loc[2]= 0.0f;
 						break;
 					case 's':
-						pchan->size[0]=pchan->size[1]=pchan->size[2]=1.0F;
+						if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
+							pchan->size[0]= 1.0f;
+						if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
+							pchan->size[1]= 1.0f;
+						if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
+							pchan->size[2]= 1.0f;
 						break;
 						
 				}

Modified: trunk/blender/source/blender/src/editobject.c
===================================================================
--- trunk/blender/source/blender/src/editobject.c	2008-03-16 01:31:14 UTC (rev 14128)
+++ trunk/blender/source/blender/src/editobject.c	2008-03-16 03:11:57 UTC (rev 14129)
@@ -1030,18 +1030,31 @@
 				 *	- with a mesh in weightpaint mode, it's related armature needs to be cleared
 				 *	- with clearing transform of object being edited at the time
 				 */
-				if ((G.f & G_WEIGHTPAINT) || ob==OBACT) {
+				if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
 					clear_armature(ob, mode);
 					armature_clear= 1;	/* silly system to prevent another dag update, so no action applied */
 				}
 			}
 			else if((G.f & G_WEIGHTPAINT)==0) {
-				
-				if(mode=='r') {
-					memset(ob->rot, 0, 3*sizeof(float));
-					memset(ob->drot, 0, 3*sizeof(float));
+				/* only clear transforms of 'normal' (not armature) object if:
+				 *	- not in weightpaint mode or editmode
+				 *	- if that object's transform locks are not enabled (this is done on a per-channel basis)
+				 */
+				if (mode=='r') {
+					/* eulers can only get cleared if they are not protected */
+					if ((ob->protectflag & OB_LOCK_ROTX)==0)
+						ob->rot[0]= ob->drot[0]= 0.0f;
+					if ((ob->protectflag & OB_LOCK_ROTY)==0)
+						ob->rot[1]= ob->drot[1]= 0.0f;
+					if ((ob->protectflag & OB_LOCK_ROTZ)==0)
+						ob->rot[2]= ob->drot[2]= 0.0f;
+					
+					/* quats here are not really used anymore anywhere, so it probably doesn't 
+					 * matter to not clear them whether the euler-based rotation is used
+					 */
 					QuatOne(ob->quat);
 					QuatOne(ob->dquat);
+					
 #ifdef WITH_VERSE
 					if(ob->vnode) {
 						struct VNode *vnode = (VNode*)ob->vnode;
@@ -1051,9 +1064,14 @@
 #endif
 
 				}
-				else if(mode=='g') {
-					memset(ob->loc, 0, 3*sizeof(float));
-					memset(ob->dloc, 0, 3*sizeof(float));
+				else if (mode=='g') {
+					if ((ob->protectflag & OB_LOCK_LOCX)==0)
+						ob->loc[0]= ob->dloc[0]= 0.0f;
+					if ((ob->protectflag & OB_LOCK_LOCY)==0)
+						ob->loc[1]= ob->dloc[1]= 0.0f;
+					if ((ob->protectflag & OB_LOCK_LOCZ)==0)
+						ob->loc[2]= ob->dloc[2]= 0.0f;
+					
 #ifdef WITH_VERSE
 					if(ob->vnode) {
 						struct VNode *vnode = (VNode*)ob->vnode;
@@ -1063,11 +1081,19 @@
 #endif
 
 				}
-				else if(mode=='s') {
-					memset(ob->dsize, 0, 3*sizeof(float));
-					ob->size[0]= 1.0;
-					ob->size[1]= 1.0;
-					ob->size[2]= 1.0;
+				else if (mode=='s') {
+					if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
+						ob->dsize[0]= 0.0f;
+						ob->size[0]= 1.0f;
+					}
+					if ((ob->protectflag & OB_LOCK_SCALEY)==0) {
+						ob->dsize[1]= 0.0f;
+						ob->size[1]= 1.0f;
+					}
+					if ((ob->protectflag & OB_LOCK_SCALEZ)==0) {
+						ob->dsize[2]= 0.0f;
+						ob->size[2]= 1.0f;
+					}
 #ifdef WITH_VERSE
 					if(ob->vnode) {
 						struct VNode *vnode = (VNode*)ob->vnode;

Modified: trunk/blender/source/blender/src/header_view3d.c
===================================================================
--- trunk/blender/source/blender/src/header_view3d.c	2008-03-16 01:31:14 UTC (rev 14128)
+++ trunk/blender/source/blender/src/header_view3d.c	2008-03-16 03:11:57 UTC (rev 14129)
@@ -1977,7 +1977,7 @@
 	block= uiNewBlock(&curarea->uiblocks, "view3d_edit_object_transformmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
 	uiBlockSetButmFunc(block, do_view3d_edit_object_transformmenu, NULL);
 	
-	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Scale/Rotationr to ObData|Ctrl A, 1",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Scale/Rotation to ObData|Ctrl A, 1",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Visual Transform|Ctrl A, 2",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Apply Deformation|Ctrl Shift A",		0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make Duplicates Real|Ctrl Shift A",		0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");





More information about the Bf-blender-cvs mailing list