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:
authorAlexander Gavrilov <angavrilov@gmail.com>2020-07-04 13:20:59 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2020-07-21 19:01:50 +0300
commitf8cc01595d1181b9a8adcb6aa930d4cbfebdc8bf (patch)
tree881dd5079bb2e7d674980a5e80d3ea7d16dd8375 /source/blender/python/intern
parent8369adabc0ec7a1fce248b688bf20860ae0434bb (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')
-rw-r--r--source/blender/python/intern/bpy_driver.c17
-rw-r--r--source/blender/python/intern/bpy_interface.c2
2 files changed, 19 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,
};
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index ed5e505176c..a880d2cd285 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -68,6 +68,7 @@
/* inittab initialization functions */
#include "../bmesh/bmesh_py_api.h"
#include "../generic/bgl.h"
+#include "../generic/bl_math_py_api.h"
#include "../generic/blf_py_api.h"
#include "../generic/idprop_py_api.h"
#include "../generic/imbuf_py_api.h"
@@ -228,6 +229,7 @@ static struct _inittab bpy_internal_modules[] = {
{"_bpy_path", BPyInit__bpy_path},
{"bgl", BPyInit_bgl},
{"blf", BPyInit_blf},
+ {"bl_math", BPyInit_bl_math},
{"imbuf", BPyInit_imbuf},
{"bmesh", BPyInit_bmesh},
#if 0