[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25736] trunk/blender/source/blender: More Driver Fixes:

Joshua Leung aligorith at gmail.com
Tue Jan 5 12:59:12 CET 2010


Revision: 25736
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25736
Author:   aligorith
Date:     2010-01-05 12:59:12 +0100 (Tue, 05 Jan 2010)

Log Message:
-----------
More Driver Fixes:
* Fixed Driver version-patching code to work correctly again with the new system.

* Fix for bug #20484, by adding a new driver variable type ('Transform Channel') which makes it easier to use object/bone transforms as in the past. The main differences with using this (compared with the 'Single Prop' type) are that this allows for 'final' transforms to get used instead (i.e. constraints are also taken into account), and also that this variable type can only be used for transforms (more limited scope -> less flexibility -> point-n-click goodies can follow). Mancandy now loads correctly again.

* Added toggle for local vs worldspace transforms when working with Rot/Loc Diff variable types, and also for the newly added Transform Channel

* Removed some dead code from sequencer...

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/blenkernel/intern/ipo.c
    trunk/blender/source/blender/editors/space_graph/graph_buttons.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_edit.c
    trunk/blender/source/blender/makesdna/DNA_anim_types.h
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2010-01-05 11:49:55 UTC (rev 25735)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2010-01-05 11:59:12 UTC (rev 25736)
@@ -329,20 +329,20 @@
 			
 			/* driver variables */
 			for (dvar= driver->variables.first; dvar; dvar=dvar->next) {
-				/* all targets (even unused ones) */
-				// XXX maybe we only need to modify the used ones, since the others can be manually fixed anyways
-				DRIVER_TARGETS_LOOPER(dvar) 
+				/* only change the used targets, since the others will need fixing manually anyway */
+				DRIVER_TARGETS_USED_LOOPER(dvar) 
 				{
 					/* rename RNA path */
 					if (dtar->rna_path)
 						dtar->rna_path= rna_path_rename_fix(dtar->id, prefix, oldName, newName, dtar->rna_path);
 					
 					/* also fix the bone-name (if applicable) */
-					if ( ((dtar->id) && (GS(dtar->id->name) == ID_OB)) &&
-						 (dtar->pchan_name[0]) && (strcmp(oldName, dtar->pchan_name)==0) )
-					{
-						BLI_strncpy(dtar->pchan_name, newName, sizeof(dtar->pchan_name));
-					}
+					// XXX this has been disabled because the old/new names have padding which means this check will fail
+					//if ( ((dtar->id) && (GS(dtar->id->name) == ID_OB)) &&
+					//	 (dtar->pchan_name[0]) && (strcmp(oldName, dtar->pchan_name)==0) )
+					//{
+					//	BLI_strncpy(dtar->pchan_name, newName, sizeof(dtar->pchan_name));
+					//}
 				}
 				DRIVER_TARGETS_LOOPER_END
 			}

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c	2010-01-05 11:49:55 UTC (rev 25735)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c	2010-01-05 11:59:12 UTC (rev 25736)
@@ -54,6 +54,7 @@
 #include "BKE_curve.h" 
 #include "BKE_global.h"
 #include "BKE_idprop.h"
+#include "BKE_object.h"
 #include "BKE_utildefines.h"
 
 #include "RNA_access.h"
@@ -922,13 +923,27 @@
 		
 		/* check if object or bone */
 		if (pchan) {
-			/* bone - need to convert to worldspace */
-			VECCOPY(tmp_loc, pchan->pose_head);
-			mul_m4_v3(ob->obmat, tmp_loc);
+			/* bone */
+			if ((dtar->flag & DTAR_FLAG_LOCALSPACE) == 0) {
+				/* convert to worldspace */
+				VECCOPY(tmp_loc, pchan->pose_head);
+				mul_m4_v3(ob->obmat, tmp_loc);
+			}
+			else {
+				/* local (use transform values directly) */
+				VECCOPY(tmp_loc, pchan->loc);
+			}
 		}
 		else {
-			/* object, already in worldspace */
-			VECCOPY(tmp_loc, ob->obmat[3]); 
+			/* object */
+			if ((dtar->flag & DTAR_FLAG_LOCALSPACE) == 0) {
+				/* worldspace */
+				VECCOPY(tmp_loc, ob->obmat[3]); 
+			}
+			else {
+				/* local (use transform values directly) */
+				VECCOPY(tmp_loc, ob->loc);
+			}
 		}
 		
 		/* copy the location to the right place */
@@ -948,6 +963,70 @@
 	return len_v3v3(loc1, loc2);
 }
 
+/* evaluate 'transform channel' driver variable */
+static float dvar_eval_transChan (ChannelDriver *driver, DriverVar *dvar)
+{
+	DriverTarget *dtar= &dvar->targets[0];
+	Object *ob= (Object *)dtar->id;
+	bPoseChannel *pchan;
+	float mat[4][4];
+	short rotOrder = 0;
+	
+	/* check if this target has valid data */
+	if ((ob == NULL) || (GS(dtar->id->name) != ID_OB)) {
+		/* invalid target, so will not have enough targets */
+		driver->flag |= DRIVER_FLAG_INVALID;
+		return 0.0f;
+	}
+	
+	/* try to get posechannel */
+	pchan= get_pose_channel(ob->pose, dtar->pchan_name);
+	
+	/* check if object or bone, and get transform matrix accordingly */
+	if (pchan) {
+		/* bone */
+		rotOrder= (pchan->rotmode > 0) ? pchan->rotmode : ROT_MODE_EUL;
+		
+		if (dtar->flag & DTAR_FLAG_LOCALSPACE)
+			copy_m4_m4(mat, pchan->chan_mat);
+		else
+			mul_m4_m4m4(mat, pchan->pose_mat, ob->obmat);
+	}
+	else {
+		/* object */
+		rotOrder= (ob->rotmode > 0) ? ob->rotmode : ROT_MODE_EUL;
+		
+		if (dtar->flag & DTAR_FLAG_LOCALSPACE)
+			object_to_mat4(ob, mat);
+		else
+			copy_m4_m4(mat, ob->obmat);
+	}
+	
+	/* check which transform */
+	if (dtar->transChan >= MAX_DTAR_TRANSCHAN_TYPES) {
+		/* not valid channel */
+		return 0.0f;
+	}
+	else if (dtar->transChan >= DTAR_TRANSCHAN_SCALEX) {
+		/* extract scale, and choose the right axis */
+		float scale[3];
+		
+		mat4_to_size(scale, mat);
+		return scale[dtar->transChan - DTAR_TRANSCHAN_SCALEX];
+	}
+	else if (dtar->transChan >= DTAR_TRANSCHAN_ROTX) {
+		/* extract euler rotation, and choose the right axis */
+		float eul[3];
+		
+		mat4_to_eulO(eul, rotOrder, mat);
+		return eul[dtar->transChan - DTAR_TRANSCHAN_ROTX];
+	}
+	else {
+		/* extract location and choose right axis */
+		return mat[3][dtar->transChan];
+	}
+}
+
 /* ......... */
 
 /* Table of Driver Varaiable Type Info Data */
@@ -971,7 +1050,14 @@
 		2, /* number of targets used */
 		{"Object/Bone 1", "Object/Bone 2"}, /* UI names for targets */
 		{DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY, DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY} /* flags */
-	END_DVAR_TYPEDEF
+	END_DVAR_TYPEDEF,
+	
+	BEGIN_DVAR_TYPEDEF(DVAR_TYPE_TRANSFORM_CHAN)
+		dvar_eval_transChan, /* eval callback */
+		1, /* number of targets used */
+		{"Object/Bone"}, /* UI names for targets */
+		{DTAR_FLAG_STRUCT_REF|DTAR_FLAG_ID_OB_ONLY} /* flags */
+	END_DVAR_TYPEDEF,
 };
 
 /* Get driver variable typeinfo */

Modified: trunk/blender/source/blender/blenkernel/intern/ipo.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/ipo.c	2010-01-05 11:49:55 UTC (rev 25735)
+++ trunk/blender/source/blender/blenkernel/intern/ipo.c	2010-01-05 11:59:12 UTC (rev 25736)
@@ -295,10 +295,7 @@
 			*array_index= 1; return "rotation_euler";
 		case AC_EUL_Z:
 			*array_index= 2; return "rotation_euler";
-			
-		case -1: /* special case for euler-rotations used by old drivers */
-			*array_index= 0; return "rotation_euler";
-			
+		
 		case AC_LOC_X:
 			*array_index= 0; return "location";
 		case AC_LOC_Y:
@@ -944,14 +941,17 @@
 		strcpy(buf, ""); /* empty string */
 	BLI_dynstr_append(path, buf);
 	
-	/* append property to path (only if applicable) */
-	if (blocktype > 0) {
-		/* need to add dot before property if there was anything precceding this */
-		if (buf[0])
-			BLI_dynstr_append(path, ".");
-		
-		/* now write name of property */
-		BLI_dynstr_append(path, propname);
+	/* need to add dot before property if there was anything precceding this */
+	if (buf[0])
+		BLI_dynstr_append(path, ".");
+	
+	/* now write name of property */
+	BLI_dynstr_append(path, propname);
+	
+	/* if there was no array index pointer provided, add it to the path */
+	if (array_index == NULL) {
+		sprintf(buf, "[\"%d\"]", dummy_index);
+		BLI_dynstr_append(path, buf);
 	}
 	
 	/* convert to normal MEM_malloc'd string */
@@ -965,6 +965,36 @@
 /* *************************************************** */
 /* Conversion Utilities */
 
+/* Convert adrcodes to driver target transform channel types */
+static short adrcode_to_dtar_transchan (short adrcode)
+{
+	switch (adrcode) {
+		case OB_LOC_X:	
+			return DTAR_TRANSCHAN_LOCX;
+		case OB_LOC_Y:
+			return DTAR_TRANSCHAN_LOCY;
+		case OB_LOC_Z:
+			return DTAR_TRANSCHAN_LOCZ;
+		
+		case OB_ROT_X:	
+			return DTAR_TRANSCHAN_ROTX;
+		case OB_ROT_Y:
+			return DTAR_TRANSCHAN_ROTY;
+		case OB_ROT_Z:
+			return DTAR_TRANSCHAN_ROTZ;
+		
+		case OB_SIZE_X:	
+			return DTAR_TRANSCHAN_SCALEX;
+		case OB_SIZE_Y:
+			return DTAR_TRANSCHAN_SCALEX;
+		case OB_SIZE_Z:
+			return DTAR_TRANSCHAN_SCALEX;
+			
+		default:
+			return 0;
+	}
+}
+
 /* Convert IpoDriver to ChannelDriver - will free the old data (i.e. the old driver) */
 static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
 {
@@ -976,91 +1006,61 @@
 	/* if 'pydriver', just copy data across */
 	if (idriver->type == IPO_DRIVER_TYPE_PYTHON) {
 		/* PyDriver only requires the expression to be copied */
-		// TODO: but the expression will be useless...
+		// FIXME: expression will be useless due to API changes, but at least not totally lost
 		cdriver->type = DRIVER_TYPE_PYTHON;
-		strcpy(cdriver->expression, idriver->name); // XXX is this safe? 
+		if (idriver->name[0])
+			BLI_strncpy(cdriver->expression, idriver->name, sizeof(cdriver->expression));
 	}
-#if 0 // XXX needs changes for the new system
 	else {
-		DriverTarget *dtar=NULL, *dtar2=NULL;
+		DriverVar *dvar = NULL;
+		DriverTarget *dtar = NULL;
 		
-		/* what to store depends on the 'blocktype' (ID_OB or ID_PO - object or posechannel) */
-		if (idriver->blocktype == ID_AR) {
-			/* ID_PO */
+		/* this should be ok for all types here... */
+		cdriver->type= DRIVER_TYPE_AVERAGE;
+		
+		/* what to store depends on the 'blocktype' - object or posechannel */
+		if (idriver->blocktype == ID_AR) { /* PoseChannel */
 			if (idriver->adrcode == OB_ROT_DIFF) {
-				/* Rotational Difference is a special type of driver now... */
-				cdriver->type= DRIVER_TYPE_ROTDIFF;
+				/* Rotational Difference requires a special type of variable */
+				dvar= driver_add_new_variable(cdriver);
+				driver_change_variable_type(dvar, DVAR_TYPE_ROT_DIFF);
 				
-				/* make 2 driver targets */
-				dtar= driver_add_new_target(cdriver);
-				dtar2= driver_add_new_target(cdriver);
+					/* first bone target */
+				dtar= &dvar->targets[0];
+				dtar->id= (ID *)idriver->ob;
+				if (idriver->name[0])
+					BLI_strncpy(dtar->pchan_name, idriver->name, 32);
 				
-				/* driver must use bones from same armature... */
-				dtar->id= dtar2->id= (ID *)idriver->ob;
-				
-				/* paths for the two targets get the pointers to the relevant Pose-Channels 
-				 *	- return pointers to Pose-Channels not rotation channels, as calculation code is picky
-				 *	- old bone names were stored in same var, in idriver->name
-				 *
-				 *	- we use several hacks here - blocktype == -1 specifies that no property needs to be found, and
-				 *	  providing a name for 'actname' will automatically imply Pose-Channel with name 'actname'
-				 */
-				dtar->rna_path= get_rna_access(-1, -1, idriver->name, NULL, NULL);
-				dtar2->rna_path= get_rna_access(-1, -1, idriver->name+DRIVER_NAME_OFFS, NULL, NULL);
+					/* second bone target (name was stored in same var as the first one) */
+				dtar= &dvar->targets[1];
+				dtar->id= (ID *)idriver->ob;
+				if (idriver->name[0]) // xxx... for safety
+					BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, 32);
 			}
 			else {
-				/* 'standard' driver */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list