[Bf-blender-cvs] [bbb5ed3] object_nodes: Function for converting a bNodeTree into the internal low-level bvm node graph.

Lukas Tönne noreply at git.blender.org
Tue Nov 24 09:42:51 CET 2015


Commit: bbb5ed35b1d222dc3a12182bc3612270116fb16b
Author: Lukas Tönne
Date:   Fri Oct 9 15:33:08 2015 +0200
Branches: object_nodes
https://developer.blender.org/rBbbb5ed35b1d222dc3a12182bc3612270116fb16b

Function for converting a bNodeTree into the internal low-level bvm node graph.

===================================================================

M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/CMakeLists.txt
M	source/blender/blenvm/intern/bvm_api.cc

===================================================================

diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index fbc454d..6e43f38 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -57,6 +57,19 @@ const char *BVM_function_name(const struct BVMFunction *fun);
 
 void BVM_expression_eval(struct BVMExpression *expr, void *result);
 
+/* ------------------------------------------------------------------------- */
+
+struct BVMNodeGraph;
+struct BVMNodeInstance;
+
+struct BVMNodeInstance *BVM_nodegraph_add_node(struct BVMNodeGraph *graph, const char *type, const char *name);
+
+/* ------------------------------------------------------------------------- */
+
+struct bNodeTree;
+
+struct BVMExpression *BVM_gen_nodetree_expression(struct bNodeTree *ntree);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index 953d22b..33a20f3 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -26,8 +26,10 @@
 set(INC
 	.
 	util
+	../blenkernel
 	../blenlib
 	../makesdna
+	../makesrna
 	../../../intern/guardedalloc
 )
 
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 441a497..e968f96 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -32,14 +32,22 @@
 #include "MEM_guardedalloc.h"
 
 extern "C" {
+#include "BLI_utildefines.h"
+
+#include "DNA_node_types.h"
+
+#include "BKE_node.h"
+
 #include "BVM_api.h"
 }
 
 #include "bvm_expression.h"
 #include "bvm_function.h"
 #include "bvm_module.h"
+#include "bvm_nodegraph.h"
 
-#define _MOD(mod) ((bvm::Module *)(mod))
+BLI_INLINE bvm::Module *_MOD(struct BVMModule *mod)
+{ return (bvm::Module *)mod; }
 
 struct BVMModule *BVM_module_create(void)
 { return (struct BVMModule *)(new bvm::Module()); }
@@ -53,6 +61,53 @@ struct BVMFunction *BVM_module_create_function(BVMModule *mod, const char *name)
 bool BVM_module_delete_function(BVMModule *mod, const char *name)
 { return _MOD(mod)->remove_function(name); }
 
-#undef _MOD
+/* ------------------------------------------------------------------------- */
+
+BLI_INLINE bvm::NodeGraph *_GRAPH(struct BVMNodeGraph *graph)
+{ return (bvm::NodeGraph *)graph; }
+
+BLI_INLINE bvm::NodeInstance *_NODE(struct BVMNodeInstance *node)
+{ return (bvm::NodeInstance *)node; }
+
+struct BVMNodeInstance *BVM_nodegraph_add_node(BVMNodeGraph *graph, const char *type, const char *name)
+{ return (struct BVMNodeInstance *)_GRAPH(graph)->add_node(type, name); }
+
+/* ------------------------------------------------------------------------- */
+
+static void gen_nodetree_nodegraph(bNodeTree *btree, bvm::NodeGraph &graph)
+{
+	for (bNode *bnode = (bNode*)btree->nodes.first; bnode; bnode = bnode->next) {
+		BLI_assert(bnode->typeinfo != NULL);
+		if (!nodeIsRegistered(bnode))
+			continue;
+		
+		const char *type = bnode->typeinfo->idname;
+		/*NodeInstance *node =*/ graph.add_node(type, bnode->name);
+	}
+	
+	for (bNodeLink *blink = (bNodeLink *)btree->links.first; blink; blink = blink->next) {
+		if (!(blink->flag & NODE_LINK_VALID))
+			continue;
+		
+		graph.add_link(blink->fromnode->name, blink->fromsock->name,
+		               blink->tonode->name, blink->tosock->name);
+	}
+}
+
+struct BVMExpression *BVM_gen_nodetree_expression(bNodeTree *btree)
+{
+	using namespace bvm;
+	
+	NodeGraph graph;
+	
+	gen_nodetree_nodegraph(btree, graph);
+	
+	// XXX TODO call codegen function here to turn nodegraph into an expression
+	Expression *expr = NULL;
+	
+	return (BVMExpression *)expr;
+}
+
+#undef _GRAPH
 
 #undef _EXPR




More information about the Bf-blender-cvs mailing list