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:
authorWillian Padovani Germano <wpgermano@gmail.com>2006-04-30 20:22:31 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2006-04-30 20:22:31 +0400
commit89dab4397d9eb2b9970ba28edeaf95c578dcaab4 (patch)
tree267c2faf6a9f2475630df2894a5e24832bc9ace4 /source/blender/python/api2_2x/EXPP_interface.c
parent3b84767824d4f9666dfc5eea1fcf134d7643fb27 (diff)
Pydrivers: Ipo Drivers controlled by Python expressions
wiki with info: http://mediawiki.blender.org/index.php/BlenderDev/PyDrivers (there are two sample .blends in the patch tracker entry, last link in the wiki page) Notes: In usiblender.c I just made Python exit before the main library gets freed. I found a situation with pydrivers where py's gc tried to del objects on exit and their ID's were not valid anymore (so sigsegv). Ton needs to check the depsgraph part. For now pydrivers can reference their own object, something normal ipodrivers can't. This seems to work fine and is quite useful, but if tests prove the restriction is necessary, we just need to uncomment a piece of code in EXPP_interface.c, marked with "XXX". Thanks Ton for the ipodrivers code and adding the hooks for the py part and Martin for the "Button Python Evaluation" patch from which I started this one. Anyone interested, please check the wiki, the .blends (they have README's) and tell me about any issue.
Diffstat (limited to 'source/blender/python/api2_2x/EXPP_interface.c')
-rw-r--r--source/blender/python/api2_2x/EXPP_interface.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/EXPP_interface.c b/source/blender/python/api2_2x/EXPP_interface.c
index 9f20db03c07..ee8b04ebde9 100644
--- a/source/blender/python/api2_2x/EXPP_interface.c
+++ b/source/blender/python/api2_2x/EXPP_interface.c
@@ -34,6 +34,9 @@
#include "EXPP_interface.h"
#include "BLI_blenlib.h"
+#include "MEM_guardedalloc.h"
+#include "BLI_linklist.h" /* linked list: LinkNode struct and functions */
+#include "DNA_object_types.h"
#include "DNA_space_types.h" /* for FILE_MAXDIR, FILE_MAXFILE */
#include "Blender.h"
@@ -129,3 +132,99 @@ char *bpy_gethome(int append_scriptsdir)
return NULL;
}
+
+/* PyDrivers */
+
+/*
+ * Pydrivers are Blender Ipo Drivers defined by Python expressions.
+ * We need to tell DAG about objects used in these expressions, so we
+ * eval each expression to collect the ob refs. in it.
+ */
+
+/* these are checked for example in Object.c: M_Object_Get (Object.Get())
+ * to collect the refs. */
+static int pydriver_running = 0;
+
+int bpy_during_pydriver(void)
+{
+ return pydriver_running;
+}
+
+void bpy_pydriver_running(int state)
+{
+ pydriver_running = state;
+}
+
+/* Obj references are collected in this extern linked list: */
+LinkNode *bpy_pydriver_oblist = NULL;
+
+void bpy_pydriver_freeList(void)
+{
+ BLI_linklist_free(bpy_pydriver_oblist, NULL);
+ bpy_pydriver_oblist = NULL;
+}
+
+void bpy_pydriver_appendToList(struct Object *ob)
+{
+ LinkNode *ln = bpy_pydriver_oblist;
+
+ /* check that the expression is not referencing its owner object */
+
+/* XXX COMMENTED OUT TO TEST IF WE REALLY NEED TO IMPOSE THIS RESTRICTION
+ if (ln && ln->link) {
+ if (ob == (Object *)ln->link) {
+ PyErr_SetString(PyExc_AttributeError,
+ "Python driver expression can't reference its own object");
+ return;
+ }
+ else
+ ln = ln->next;
+ }
+*/
+ while (ln) { /* is ob already in list? ... */
+ if (ob == (Object *)ln->link)
+ break;
+ ln = ln->next;
+ }
+
+ if (!ln) /* ... not yet, append it */
+ BLI_linklist_append(&bpy_pydriver_oblist, (void *)ob);
+
+ return;
+}
+
+/* Get an array from our linked list of objs referenced in the
+ * current pydriver. The first node in the list is discarded,
+ * since it is the actual pydriver owner, which shouldn't be
+ * passed to the depsgraph (no self references). */
+struct Object **bpy_pydriver_obArrayFromList(void)
+{
+ Object **obarray = NULL;
+
+ if (bpy_pydriver_oblist) {
+ int i;
+ short len = BLI_linklist_length(bpy_pydriver_oblist);
+
+ if (len > 1) {
+
+ obarray = (Object **)MEM_mallocN(sizeof(Object*)*len,
+ "pydriver array");
+
+ if (obarray) {
+ LinkNode *ln = bpy_pydriver_oblist;
+ ln = ln->next; /* skip first ob, which is the pydriver owner */
+
+ for (i = 0; i < len-1; i++) {
+ obarray[i] = (Object *)ln->link;
+ ln = ln->next;
+ }
+
+ obarray[len-1] = NULL; /* NULL-terminated array */
+ }
+ }
+ bpy_pydriver_freeList();
+ }
+
+ return obarray;
+}
+