From 47416c725c9790c17abddfbcd96c080e28e76abb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Dec 2009 19:59:04 +0000 Subject: [PATCH] driver type 'Sum' --- source/blender/blenkernel/intern/fcurve.c | 14 +++++++++----- source/blender/makesdna/DNA_anim_types.h | 2 ++ source/blender/makesrna/intern/rna_fcurve.c | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 0623a5cbe5e..b3a6b773cf3 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -910,6 +910,7 @@ static float evaluate_driver (ChannelDriver *driver, float evaltime) // TODO: the flags for individual targets need to be used too for more fine-grained support... switch (driver->type) { case DRIVER_TYPE_AVERAGE: /* average values of driver targets */ + case DRIVER_TYPE_SUM: /* sum values of driver targets */ { /* check how many targets there are first (i.e. just one?) */ if (driver->targets.first == driver->targets.last) { @@ -921,19 +922,22 @@ static float evaluate_driver (ChannelDriver *driver, float evaltime) /* more than one target, so average the values of the targets */ int tot = 0; float value = 0.0f; - + /* loop through targets, adding (hopefully we don't get any overflow!) */ for (dtar= driver->targets.first; dtar; dtar=dtar->next) { - value += driver_get_target_value(driver, dtar); + value += driver_get_target_value(driver, dtar); tot++; } - + /* return the average of these */ - return (value / (float)tot); + if(driver->type == DRIVER_TYPE_AVERAGE) + return (value / (float)tot); + else + return value; + } } break; - case DRIVER_TYPE_PYTHON: /* expression */ { #ifndef DISABLE_PYTHON diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index c6330861fd2..09f77d98f4b 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -309,6 +309,8 @@ typedef enum eDriver_Types { DRIVER_TYPE_PYTHON, /* rotational difference (must use rotation channels only) */ DRIVER_TYPE_ROTDIFF, + /* sum of all values */ + DRIVER_TYPE_SUM, } eDriver_Types; /* driver flags */ diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index fbf4a8b41c5..bf8b74d08ee 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -789,6 +789,7 @@ static void rna_def_channeldriver(BlenderRNA *brna) static EnumPropertyItem prop_type_items[] = { {DRIVER_TYPE_AVERAGE, "AVERAGE", 0, "Averaged Value", ""}, + {DRIVER_TYPE_SUM, "SUM", 0, "Sum Values", ""}, {DRIVER_TYPE_PYTHON, "SCRIPTED", 0, "Scripted Expression", ""}, {DRIVER_TYPE_ROTDIFF, "ROTDIFF", 0, "Rotational Difference", ""}, {0, NULL, 0, NULL, NULL}};