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>2016-03-27 07:57:27 +0300
committerJoshua Leung <aligorith@gmail.com>2016-03-27 08:05:35 +0300
commite12650bdd1f7d68f4325e879fe6551163f709f2f (patch)
tree9a823e4ec2ea75d0ce78ab70f384dba938b472d9 /source/blender/editors/animation/drivers.c
parent4b279815d562511443509cdfda7fe0e77666db67 (diff)
Driver Eyedropper: Auto detection/correction magic for rotation properties
When linking a rotation property to a non-rotation property (going in either direction - i.e. rot -> normal, normal -> rot), the driver expression will now be set so that the new drivers behave as expected (i.e. you get the values you see, instead of "weird" values that seem several orders of magnitude off). This may not be that great for everyone (i.e. the rare users out there who actually like to look at their rotations in radians), but they usually know what they're doing anyway, so this will be easy to correct.
Diffstat (limited to 'source/blender/editors/animation/drivers.c')
-rw-r--r--source/blender/editors/animation/drivers.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index 1ebe4f48302..66e3cceba49 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -178,6 +178,7 @@ static int add_driver_with_target(
ReportList *reports,
ID *dst_id, const char dst_path[], int dst_index,
ID *src_id, const char src_path[], int src_index,
+ PointerRNA *dst_ptr, PropertyRNA *dst_prop,
PointerRNA *src_ptr, PropertyRNA *src_prop,
short flag, int driver_type)
{
@@ -194,7 +195,34 @@ static int add_driver_with_target(
/* Set the type of the driver */
driver->type = driver_type;
- BLI_strncpy(driver->expression, "var", sizeof(driver->expression)); /* XXX: if we have N-1 mapping, we need to include all those here... */
+
+ /* Set driver expression, so that the driver works out of the box
+ *
+ * The following checks define a bit of "autodetection magic" we use
+ * to ensure that the drivers will behave as expected out of the box
+ * when faced with properties with different units.
+ */
+ /* XXX: if we have N-1 mapping, should we include all those in the expression? */
+ if ((RNA_property_unit(dst_prop) == PROP_UNIT_ROTATION) &&
+ (RNA_property_unit(src_prop) != PROP_UNIT_ROTATION))
+ {
+ /* Rotation Destination: normal -> radians, so convert src to radians
+ * (However, if both input and output is a rotation, don't apply such corrections)
+ */
+ BLI_strncpy(driver->expression, "radians(var)", sizeof(driver->expression));
+ }
+ else if ((RNA_property_unit(src_prop) == PROP_UNIT_ROTATION) &&
+ (RNA_property_unit(dst_prop) != PROP_UNIT_ROTATION))
+ {
+ /* Rotation Source: radians -> normal, so convert src to degrees
+ * (However, if both input and output is a rotation, don't apply such corrections)
+ */
+ BLI_strncpy(driver->expression, "degrees(var)", sizeof(driver->expression));
+ }
+ else {
+ /* Just a normal property without any unit problems */
+ BLI_strncpy(driver->expression, "var", sizeof(driver->expression));
+ }
/* Create a driver variable for the target
* - For transform properties, we want to automatically use "transform channel" instead
@@ -323,7 +351,7 @@ int ANIM_add_driver_with_target(
int i;
for (i = 0; i < len; i++) {
- done_tot += add_driver_with_target(reports, dst_id, dst_path, i, src_id, src_path, i, &ptr2, prop2, flag, driver_type);
+ done_tot += add_driver_with_target(reports, dst_id, dst_path, i, src_id, src_path, i, &ptr, prop, &ptr2, prop2, flag, driver_type);
}
break;
}
@@ -335,14 +363,14 @@ int ANIM_add_driver_with_target(
int i;
for (i = 0; i < len; i++) {
- done_tot += add_driver_with_target(reports, dst_id, dst_path, i, src_id, src_path, src_index, &ptr2, prop2, flag, driver_type);
+ done_tot += add_driver_with_target(reports, dst_id, dst_path, i, src_id, src_path, src_index, &ptr, prop, &ptr2, prop2, flag, driver_type);
}
break;
}
case CREATEDRIVER_MAPPING_1_1: /* 1-1 - Use the specified index (unless -1) */
{
- done_tot = add_driver_with_target(reports, dst_id, dst_path, dst_index, src_id, src_path, src_index, &ptr2, prop2, flag, driver_type);
+ done_tot = add_driver_with_target(reports, dst_id, dst_path, dst_index, src_id, src_path, src_index, &ptr, prop, &ptr2, prop2, flag, driver_type);
break;
}
}