diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2020-07-04 13:20:59 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2020-07-21 19:01:50 +0300 |
commit | f8cc01595d1181b9a8adcb6aa930d4cbfebdc8bf (patch) | |
tree | 881dd5079bb2e7d674980a5e80d3ea7d16dd8375 /source/blender/python/intern/bpy_driver.c | |
parent | 8369adabc0ec7a1fce248b688bf20860ae0434bb (diff) |
Drivers: add lerp and clamp functions to namespace.
Implementation of lerp without a function requires repeating one of
the arguments, which is not ideal. To avoid that, add a new function
to the driver namespace. In addition, provide a function for clamping
between 0 and 1 to support easy clamped lerp, and a smoothstep function
from GLSL that is somewhat related.
The function implementations are added to a new bl_math module.
As an aside, add the round function and two-argument log to the
pylike expression subset.
Differential Revision: https://developer.blender.org/D8205
Diffstat (limited to 'source/blender/python/intern/bpy_driver.c')
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 3d83eb90da6..5e2162c9e2d 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -114,6 +114,19 @@ int bpy_pydriver_create_dict(void) Py_DECREF(mod); } + /* Add math utility functions. */ + mod = PyImport_ImportModuleLevel("bl_math", NULL, NULL, NULL, 0); + if (mod) { + static const char *names[] = {"clamp", "lerp", "smoothstep", NULL}; + + for (const char **pname = names; *pname; ++pname) { + PyObject *func = PyDict_GetItemString(PyModule_GetDict(mod), *pname); + PyDict_SetItemString(bpy_pydriver_Dict, *pname, func); + } + + Py_DECREF(mod); + } + #ifdef USE_BYTECODE_WHITELIST /* setup the whitelist */ { @@ -133,6 +146,10 @@ int bpy_pydriver_create_dict(void) "bool", "float", "int", + /* bl_math */ + "clamp", + "lerp", + "smoothstep", NULL, }; |