Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2010-01-05 14:59:12 +0300
committerJoshua Leung <aligorith@gmail.com>2010-01-05 14:59:12 +0300
commit6fb1d0e6a371ef66a2a3598c3a919ce63b64a22c (patch)
treee9345226f302f9d9cf38474bb9c21298514e94af /source/blender/blenkernel/intern
parentcce1d178b8ea9ac948ca7be4017a28b57dda6785 (diff)
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...
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c16
-rw-r--r--source/blender/blenkernel/intern/fcurve.c98
-rw-r--r--source/blender/blenkernel/intern/ipo.c166
3 files changed, 181 insertions, 99 deletions
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 4c63c64ccb9..8b86f6a5d1f 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -329,20 +329,20 @@ static void fcurves_path_rename_fix (ID *owner_id, char *prefix, char *oldName,
/* 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
}
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 9e84727fbf1..67bee90e91c 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -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 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar)
/* 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 @@ static float dvar_eval_locDiff (ChannelDriver *driver, DriverVar *dvar)
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 @@ DriverVarTypeInfo dvar_types[MAX_DVAR_TYPES] = {
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 */
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index 988bd429185..feb7fc3e382 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -295,10 +295,7 @@ static char *pchan_adrcodes_to_paths (int adrcode, int *array_index)
*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 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
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 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
/* *************************************************** */
/* 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 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
/* 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;
-
- /* make 2 driver targets */
- dtar= driver_add_new_target(cdriver);
- dtar2= driver_add_new_target(cdriver);
+ /* Rotational Difference requires a special type of variable */
+ dvar= driver_add_new_variable(cdriver);
+ driver_change_variable_type(dvar, DVAR_TYPE_ROT_DIFF);
- /* driver must use bones from same armature... */
- dtar->id= dtar2->id= (ID *)idriver->ob;
+ /* first bone target */
+ dtar= &dvar->targets[0];
+ dtar->id= (ID *)idriver->ob;
+ if (idriver->name[0])
+ BLI_strncpy(dtar->pchan_name, idriver->name, 32);
- /* 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 */
- cdriver->type= DRIVER_TYPE_AVERAGE;
+ /* only a single variable, of type 'transform channel' */
+ dvar= driver_add_new_variable(cdriver);
+ driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);
- /* make 1 driver target */
- dtar= driver_add_new_target(cdriver);
+ /* only requires a single target */
+ dtar= &dvar->targets[0];
dtar->id= (ID *)idriver->ob;
-
- switch (idriver->adrcode) {
- case OB_LOC_X: /* x,y,z location are quite straightforward */
- dtar->rna_path= get_rna_access(ID_PO, AC_LOC_X, idriver->name, NULL, &dtar->array_index);
- break;
- case OB_LOC_Y:
- dtar->rna_path= get_rna_access(ID_PO, AC_LOC_Y, idriver->name, NULL, &dtar->array_index);
- break;
- case OB_LOC_Z:
- dtar->rna_path= get_rna_access(ID_PO, AC_LOC_Z, idriver->name, NULL, &dtar->array_index);
- break;
-
- case OB_SIZE_X: /* x,y,z scaling are also quite straightforward */
- dtar->rna_path= get_rna_access(ID_PO, AC_SIZE_X, idriver->name, NULL, &dtar->array_index);
- break;
- case OB_SIZE_Y:
- dtar->rna_path= get_rna_access(ID_PO, AC_SIZE_Y, idriver->name, NULL, &dtar->array_index);
- break;
- case OB_SIZE_Z:
- dtar->rna_path= get_rna_access(ID_PO, AC_SIZE_Z, idriver->name, NULL, &dtar->array_index);
- break;
-
- case OB_ROT_X: /* rotation - we need to be careful with this... */
- case OB_ROT_Y:
- case OB_ROT_Z:
- {
- /* -1 here, not rotation code, since old system didn't have eulers */
- dtar->rna_path= get_rna_access(ID_PO, -1, idriver->name, NULL, NULL);
- dtar->array_index= idriver->adrcode - OB_ROT_X;
- }
- break;
- }
+ if (idriver->name[0])
+ BLI_strncpy(dtar->pchan_name, idriver->name, 32);
+ dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
}
}
- else {
- /* ID_OB */
- cdriver->type= DRIVER_TYPE_AVERAGE;
-
- /* make 1 driver target */
- dtar= driver_add_new_target(cdriver);
+ else { /* Object */
+ /* only a single variable, of type 'transform channel' */
+ dvar= driver_add_new_variable(cdriver);
+ driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);
+ /* only requires single target */
+ dtar= &dvar->targets[0];
dtar->id= (ID *)idriver->ob;
- dtar->rna_path= get_rna_access(ID_OB, idriver->adrcode, NULL, NULL, &dtar->array_index);
+ dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
}
}
-#endif // XXX fixme
/* return the new one */
return cdriver;
@@ -1295,11 +1295,7 @@ static void icu_to_fcurves (ListBase *groups, ListBase *list, IpoCurve *icu, cha
DriverVar *dvar= fcu->driver->variables.first;
DriverTarget *dtar= &dvar->targets[0];
- /* since drivers could only be for objects, we should just check for 'rotation' being
- * in the name of the path given
- * - WARNING: this will break if we encounter a bone or object explictly named in that way...
- */
- if ((dtar && dtar->rna_path) && strstr(dtar->rna_path, "rotation")) {
+ if (ELEM3(dtar->transChan, DTAR_TRANSCHAN_ROTX, DTAR_TRANSCHAN_ROTY, DTAR_TRANSCHAN_ROTZ)) {
const float fac= (float)M_PI / 180.0f;
dst->vec[0][0] *= fac;