[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57347] trunk/blender: Custom Group Node type for extending existing nodes from python scripts.

Lukas Toenne lukas.toenne at googlemail.com
Mon Jun 10 14:19:39 CEST 2013


Revision: 57347
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57347
Author:   lukastoenne
Date:     2013-06-10 12:19:39 +0000 (Mon, 10 Jun 2013)
Log Message:
-----------
Custom Group Node type for extending existing nodes from python scripts. This is a sort of workaround for the lack of APIs in our existing node systems (compositor, cycles, BI, textures). These systems
don't have any way to deal with scripted node types yet, which could in principle by added with pynodes. The NodeCustomGroup type adds a way of scripting nodes by automating node groups which the
hardcoded system can then interpret like regular groups.

The new NodeCustomGroup type has the basic node_tree pointer property like the regular group node types and also uses the same socket interface system as regular groups. This means that input/output
sockets can be mapped to internal nodes in the same way as regular node groups in renderers and the compositor. On top of that, however, the NodeCustomGroup type can be subclassed in python scripts to flesh out
scripted node types with own draw functions, properties, updates and so on.

NB: Only cycles currently supports this node type and its derivatives, other systems may follow later.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_shader.cpp
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c

Modified: trunk/blender/intern/cycles/blender/blender_shader.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_shader.cpp	2013-06-10 12:17:36 UTC (rev 57346)
+++ trunk/blender/intern/cycles/blender/blender_shader.cpp	2013-06-10 12:19:39 UTC (rev 57347)
@@ -705,10 +705,13 @@
 				graph->add(proxy);
 			}
 		}
-		else if (b_node->is_a(&RNA_ShaderNodeGroup)) {
+		else if (b_node->is_a(&RNA_ShaderNodeGroup) || b_node->is_a(&RNA_NodeCustomGroup)) {
 			
-			BL::NodeGroup b_gnode(*b_node);
-			BL::ShaderNodeTree b_group_ntree(b_gnode.node_tree());
+			BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL);
+			if (b_node->is_a(&RNA_ShaderNodeGroup))
+				b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(*b_node)).node_tree());
+			else
+				b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(*b_node)).node_tree());
 			ProxyMap group_proxy_input_map, group_proxy_output_map;
 			
 			/* Add a proxy node for each socket

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-06-10 12:17:36 UTC (rev 57346)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-06-10 12:19:39 UTC (rev 57347)
@@ -201,6 +201,7 @@
 #include "ED_node.h"
 #include "ED_render.h"
 
+#include "NOD_common.h"
 #include "NOD_socket.h"
 
 #include "RE_engine.h"
@@ -2317,6 +2318,25 @@
 	}
 }
 
+static StructRNA *rna_NodeCustomGroup_register(Main *bmain, ReportList *reports,
+                                               void *data, const char *identifier,
+                                               StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+{
+	bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_NodeCustomGroup, data, identifier, validate, call, free);
+	if (!nt)
+		return NULL;
+	
+	/* this updates the group node instance from the tree's interface */
+	nt->verifyfunc = node_group_verify;
+	
+	nodeRegisterType(nt);
+	
+	/* update while blender is running */
+	WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
+	
+	return nt->ext.srna;
+}
+
 static void rna_CompositorNode_tag_need_exec(bNode *node)
 {
 	node->need_exec = TRUE;
@@ -2861,6 +2881,19 @@
 	RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
 }
 
+static void def_custom_group(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	
+	srna = RNA_def_struct(brna, "NodeCustomGroup", "Node");
+	RNA_def_struct_ui_text(srna, "Custom Group", "Base node type for custom registered node group types");
+	RNA_def_struct_sdna(srna, "bNode");
+
+	RNA_def_struct_register_funcs(srna, "rna_NodeCustomGroup_register", "rna_Node_unregister", NULL);
+
+	def_group(srna);
+}
+
 static void def_frame(StructRNA *srna)
 {
 	PropertyRNA *prop; 
@@ -7306,6 +7339,7 @@
 	define_specific_node(brna, "ShaderNodeGroup", "ShaderNode", "Group", "", def_group);
 	define_specific_node(brna, "CompositorNodeGroup", "CompositorNode", "Group", "", def_group);
 	define_specific_node(brna, "TextureNodeGroup", "TextureNode", "Group", "", def_group);
+	def_custom_group(brna);
 	
 	/* special socket types */
 	rna_def_cmp_output_file_slot_file(brna);




More information about the Bf-blender-cvs mailing list