diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-30 05:39:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-30 05:39:55 +0400 |
commit | 33955940e4931e2184434393e0f8c15c36a5c3c6 (patch) | |
tree | 7b3c10343162a256e85ff4346f57122032715e82 /release/scripts/templates_py/driver_functions.py | |
parent | e12354c4c5850864f925d22f53ec31578384bc63 (diff) |
add templates menu for OSL, use preprocessor directive color for decorators in python.
Diffstat (limited to 'release/scripts/templates_py/driver_functions.py')
-rw-r--r-- | release/scripts/templates_py/driver_functions.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/release/scripts/templates_py/driver_functions.py b/release/scripts/templates_py/driver_functions.py new file mode 100644 index 00000000000..1c6af0e574f --- /dev/null +++ b/release/scripts/templates_py/driver_functions.py @@ -0,0 +1,35 @@ +# This script defines functions to be used directly in drivers expressions to +# extend the builtin set of python functions. +# +# This can be executed on manually or set to 'Register' to +# initialize thefunctions on file load. + + +# two sample functions +def invert(f): + """ Simple function call: + + invert(val) + """ + return 1.0 - f + + +uuid_store = {} + + +def slow_value(value, fac, uuid): + """ Delay the value by a factor, use a unique string to allow + use in multiple drivers without conflict: + + slow_value(val, 0.5, "my_value") + """ + value_prev = uuid_store.get(uuid, value) + uuid_store[uuid] = value_new = (value_prev * fac) + (value * (1.0 - fac)) + return value_new + + +import bpy + +# Add variable defined in this script into the drivers namespace. +bpy.app.driver_namespace["invert"] = invert +bpy.app.driver_namespace["slow_value"] = slow_value |