driver_functions.py 891 B

123456789101112131415161718192021222324252627282930313233343536
  1. # This script defines functions to be used directly in drivers expressions to
  2. # extend the builtin set of python functions.
  3. #
  4. # This can be executed on manually or set to 'Register' to
  5. # initialize thefunctions on file load.
  6. # two sample functions
  7. def invert(f):
  8. """ Simple function call:
  9. invert(val)
  10. """
  11. return 1.0 - f
  12. uuid_store = {}
  13. def slow_value(value, fac, uuid):
  14. """ Delay the value by a factor, use a unique string to allow
  15. use in multiple drivers without conflict:
  16. slow_value(val, 0.5, "my_value")
  17. """
  18. value_prev = uuid_store.get(uuid, value)
  19. uuid_store[uuid] = value_new = (value_prev * fac) + (value * (1.0 - fac))
  20. return value_new
  21. import bpy
  22. # Add variable defined in this script into the drivers namespace.
  23. bpy.app.driver_namespace["invert"] = invert
  24. bpy.app.driver_namespace["slow_value"] = slow_value