[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41023] trunk/blender: - add template for defining custom driver functions.

Campbell Barton ideasman42 at gmail.com
Sat Oct 15 09:19:35 CEST 2011


Revision: 41023
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41023
Author:   campbellbarton
Date:     2011-10-15 07:19:34 +0000 (Sat, 15 Oct 2011)
Log Message:
-----------
- add template for defining custom driver functions.
- comment unused assignments.

Modified Paths:
--------------
    trunk/blender/GNUmakefile
    trunk/blender/source/blender/nodes/intern/node_exec.c

Added Paths:
-----------
    trunk/blender/release/scripts/templates/driver_functions.py

Modified: trunk/blender/GNUmakefile
===================================================================
--- trunk/blender/GNUmakefile	2011-10-15 05:01:47 UTC (rev 41022)
+++ trunk/blender/GNUmakefile	2011-10-15 07:19:34 UTC (rev 41023)
@@ -233,7 +233,7 @@
 doc_py:
 	$(BUILD_DIR)/bin/blender --background --factory-startup --python doc/python_api/sphinx_doc_gen.py
 	cd doc/python_api ; sphinx-build -n -b html sphinx-in sphinx-out
-	@echo "docs written into: 'doc/python_api/sphinx-out/index.html'"
+	@echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/contents.html'"
 
 
 clean:

Added: trunk/blender/release/scripts/templates/driver_functions.py
===================================================================
--- trunk/blender/release/scripts/templates/driver_functions.py	                        (rev 0)
+++ trunk/blender/release/scripts/templates/driver_functions.py	2011-10-15 07:19:34 UTC (rev 41023)
@@ -0,0 +1,34 @@
+# 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

Modified: trunk/blender/source/blender/nodes/intern/node_exec.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/node_exec.c	2011-10-15 05:01:47 UTC (rev 41022)
+++ trunk/blender/source/blender/nodes/intern/node_exec.c	2011-10-15 07:19:34 UTC (rev 41023)
@@ -180,7 +180,7 @@
 	
 	/* prepare group tree inputs */
 	for (sock=ntree->inputs.first; sock; sock=sock->next) {
-		ns = setup_stack(exec->stack, sock);
+		/* ns = */ setup_stack(exec->stack, sock);
 	}
 	/* prepare all internal nodes for execution */
 	for(n=0, nodeexec= exec->nodeexec; n < totnodes; ++n, ++nodeexec) {
@@ -198,7 +198,7 @@
 		
 		/* tag all outputs */
 		for (sock=node->outputs.first; sock; sock=sock->next) {
-			ns = setup_stack(exec->stack, sock);
+			/* ns = */ setup_stack(exec->stack, sock);
 		}
 		
 		if(node->typeinfo->initexecfunc)




More information about the Bf-blender-cvs mailing list