[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44322] trunk/blender/source/blender: Adds a new node type for saving multiple image files from a single node.

Lukas Toenne lukas.toenne at googlemail.com
Wed Feb 22 13:24:11 CET 2012


Revision: 44322
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44322
Author:   lukastoenne
Date:     2012-02-22 12:24:04 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
Adds a new node type for saving multiple image files from a single node.

Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:

Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'

would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...

Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.

To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.

Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is  activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.

Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/editors/space_node/node_edit.c
    trunk/blender/source/blender/editors/space_node/node_header.c
    trunk/blender/source/blender/editors/space_node/node_intern.h
    trunk/blender/source/blender/editors/space_node/node_ops.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
    trunk/blender/source/blender/nodes/NOD_composite.h
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_outputFile.c

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2012-02-22 12:11:56 UTC (rev 44321)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2012-02-22 12:24:04 UTC (rev 44322)
@@ -112,8 +112,9 @@
 typedef struct bNodeTemplate {
 	int type;
 	
-	/* group tree */
-	struct bNodeTree *ngroup;
+	struct Main *main;
+	struct Scene *scene;
+	struct bNodeTree *ngroup;	/* group tree */
 } bNodeTemplate;
 
 /** Defines a node type.
@@ -653,6 +654,7 @@
 #define CMP_NODE_TRANSFORM	264
 #define CMP_NODE_MOVIEDISTORTION	265
 #define CMP_NODE_DOUBLEEDGEMASK    266
+#define CMP_NODE_OUTPUT_MULTI_FILE	267
 
 #define CMP_NODE_GLARE		301
 #define CMP_NODE_TONEMAP	302
@@ -692,6 +694,8 @@
 void ntreeCompositForceHidden(struct bNodeTree *ntree, struct Scene *scene);
 void ntreeCompositClearTags(struct bNodeTree *ntree);
 
+void ntreeCompositOutputMultiFileAddSocket(struct bNodeTree *ntree, struct bNode *node, struct ImageFormatData *im_format);
+int ntreeCompositOutputMultiFileRemoveActiveSocket(struct bNodeTree *ntree, struct bNode *node);
 
 /* ************** TEXTURE NODES *************** */
 

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2012-02-22 12:11:56 UTC (rev 44321)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2012-02-22 12:24:04 UTC (rev 44322)
@@ -1804,6 +1804,7 @@
 	register_node_type_cmp_viewer(ttype);
 	register_node_type_cmp_splitviewer(ttype);
 	register_node_type_cmp_output_file(ttype);
+	register_node_type_cmp_output_multi_file(ttype);
 	register_node_type_cmp_view_levels(ttype);
 	
 	register_node_type_cmp_curve_rgb(ttype);

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2012-02-22 12:11:56 UTC (rev 44321)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2012-02-22 12:24:04 UTC (rev 44322)
@@ -725,6 +725,12 @@
 			else
 				writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
 		}
+		
+		if (node->type==CMP_NODE_OUTPUT_MULTI_FILE) {
+			/* inputs have own storage data */
+			for (sock=node->inputs.first; sock; sock=sock->next)
+				writestruct(wd, DATA, "NodeImageMultiFileSocket", 1, sock->storage);
+		}
 	}
 	
 	for(link= ntree->links.first; link; link= link->next)

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2012-02-22 12:11:56 UTC (rev 44321)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2012-02-22 12:24:04 UTC (rev 44322)
@@ -107,16 +107,20 @@
 								bNodeTree *ntree, bNode *node, bNodeSocket *sock,
 								const char *name, int x, int y, int width)
 {
-	PointerRNA ptr;
-	uiBut *bt;
-	
-	RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
-	
-	bt = uiDefButR(block, NUM, B_NODE_EXEC, name,
-				   x, y+1, width, NODE_DY-2, 
-				   &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
-	if (node)
-		uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
+	if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
+		node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+	else {
+		PointerRNA ptr;
+		uiBut *bt;
+		
+		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+		
+		bt = uiDefButR(block, NUM, B_NODE_EXEC, name,
+					   x, y+1, width, NODE_DY-2, 
+					   &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
+		if (node)
+			uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
+	}
 }
 
 typedef struct SocketComponentMenuArgs {
@@ -145,42 +149,80 @@
 								   bNodeTree *ntree, bNode *node, bNodeSocket *sock,
 								   const char *name, int x, int y, int width)
 {
-	PointerRNA ptr;
-	SocketComponentMenuArgs *args;
-	
-	RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
-	
-	args= MEM_callocN(sizeof(SocketComponentMenuArgs), "SocketComponentMenuArgs");
-	
-	args->ptr = ptr;
-	args->x = x;
-	args->y = y;
-	args->width = width;
-	args->cb = node_sync_cb;
-	args->arg1 = CTX_wm_space_node(C);
-	args->arg2 = node;
-	
-	uiDefBlockButN(block, socket_component_menu, args, name, x, y+1, width, NODE_DY-2, "");
+	if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
+		node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+	else {
+		PointerRNA ptr;
+		SocketComponentMenuArgs *args;
+		
+		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+		
+		args= MEM_callocN(sizeof(SocketComponentMenuArgs), "SocketComponentMenuArgs");
+		
+		args->ptr = ptr;
+		args->x = x;
+		args->y = y;
+		args->width = width;
+		args->cb = node_sync_cb;
+		args->arg1 = CTX_wm_space_node(C);
+		args->arg2 = node;
+		
+		uiDefBlockButN(block, socket_component_menu, args, name, x, y+1, width, NODE_DY-2, "");
+	}
 }
 
 static void node_socket_button_color(const bContext *C, uiBlock *block,
 							  bNodeTree *ntree, bNode *node, bNodeSocket *sock,
 							  const char *name, int x, int y, int width)
 {
-	PointerRNA ptr;
-	uiBut *bt;
-	int labelw= width - 40;
+	/* XXX would be nicer to have draw function based on sock->struct_type as well,
+	 * but currently socket types are completely identified by data type only.
+	 */
 	
-	RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
-	
-	bt=uiDefButR(block, COL, B_NODE_EXEC, "",
-				 x, y+2, (labelw>0 ? 40 : width), NODE_DY-2, 
-				 &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
-	if (node)
-		uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
-	
-	if (name[0]!='\0' && labelw>0)
-		uiDefBut(block, LABEL, 0, name, x + 40, y+2, labelw, NODE_DY-2, NULL, 0, 0, 0, 0, "");
+	switch (sock->struct_type) {
+	case SOCK_STRUCT_NONE: {
+		if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
+			node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+		else {
+			PointerRNA ptr;
+			uiBut *bt;
+			int labelw= width - 40;
+			RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+			
+			bt=uiDefButR(block, COL, B_NODE_EXEC, "",
+						 x, y+2, (labelw>0 ? 40 : width), NODE_DY-2, 
+						 &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
+			if (node)
+				uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
+			
+			if (name[0]!='\0' && labelw>0)
+				uiDefBut(block, LABEL, 0, name, x + 40, y+2, labelw, NODE_DY-2, NULL, 0, 0, 0, 0, "");
+		}
+		break;
+	}
+	case SOCK_STRUCT_OUTPUT_MULTI_FILE: {
+		uiLayout *layout, *row;
+		PointerRNA ptr, imfptr;
+		PropertyRNA *imtype_prop;
+		const char *imtype_name;
+		int rx, ry;
+		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+		imfptr = RNA_pointer_get(&ptr, "format");
+		
+		layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y+NODE_DY, width, 20, UI_GetStyle());
+		row = uiLayoutRow(layout, 0);		
+		
+		uiItemL(row, sock->name, 0);
+		imtype_prop = RNA_struct_find_property(&imfptr, "file_format");
+		RNA_property_enum_name((bContext*)C, &imfptr, imtype_prop, RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name);
+		uiBlockSetEmboss(block, UI_EMBOSSP);
+		uiItemL(row, imtype_name, 0);
+		uiBlockSetEmboss(block, UI_EMBOSSN);
+		
+		uiBlockLayoutResolve(block, &rx, &ry);
+		break;
+	}
+	}
 }
 
 /* ****************** BASE DRAW FUNCTIONS FOR NEW OPERATOR NODES ***************** */
@@ -1673,6 +1715,42 @@
 	uiItemR(row, ptr, "frame_end", 0, "End", ICON_NONE);
 }
 
+static void node_composit_buts_multi_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	uiItemL(layout, "Base Path:", 0);
+	uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE);
+}
+static void node_composit_buts_multi_file_output_details(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+	PointerRNA active_input_ptr = RNA_pointer_get(ptr, "active_input");
+	
+	node_composit_buts_multi_file_output(layout, C, ptr);
+	
+	uiItemO(layout, "Add Input", ICON_ZOOMIN, "NODE_OT_output_multi_file_add_socket");
+	
+	uiTemplateList(layout, C, ptr, "inputs", ptr, "active_input_index", NULL, 0, 0, 0);
+	
+	if (active_input_ptr.data) {
+		uiLayout *row, *col;
+		
+		uiItemS(layout);
+		
+		col = uiLayoutColumn(layout, 1);
+		uiItemL(col, "File Path:", 0);
+		row = uiLayoutRow(col, 0);
+		uiItemR(row, &active_input_ptr, "name", 0, "", 0);
+		uiItemFullO(row, "NODE_OT_output_multi_file_remove_active_socket", "", ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY);
+		
+		uiItemS(layout);
+		uiItemL(layout, "Format:", 0);
+		uiItemR(layout, &active_input_ptr, "use_render_format", 0, NULL, 0);
+		if (!RNA_boolean_get(&active_input_ptr, "use_render_format")) {
+			PointerRNA imfptr = RNA_pointer_get(&active_input_ptr, "format");
+			uiTemplateImageSettings(layout, &imfptr);
+		}
+	}
+}
+
 static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
 	uiItemR(layout, ptr, "space", 0, "", ICON_NONE);
@@ -1908,6 +1986,10 @@
 		case CMP_NODE_OUTPUT_FILE:
 			ntype->uifunc= node_composit_buts_file_output;
 			break;
+		case CMP_NODE_OUTPUT_MULTI_FILE:
+			ntype->uifunc= node_composit_buts_multi_file_output;
+			ntype->uifuncbut= node_composit_buts_multi_file_output_details;
+			break;
 		case CMP_NODE_DIFF_MATTE:
 			ntype->uifunc=node_composit_buts_diff_matte;
 			break;

Modified: trunk/blender/source/blender/editors/space_node/node_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_draw.c	2012-02-22 12:11:56 UTC (rev 44321)
+++ trunk/blender/source/blender/editors/space_node/node_draw.c	2012-02-22 12:24:04 UTC (rev 44322)
@@ -718,14 +718,8 @@
 		
 		node_socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 		
-		if (sock->link || (sock->flag & SOCK_HIDE_VALUE)) {
-			uiDefBut(node->block, LABEL, 0, sock->name, sock->locx+NODE_DYS, sock->locy-NODE_DYS, node->width-NODE_DY, NODE_DY,
-					 NULL, 0, 0, 0, 0, "");
-		}
-		else {
-			if (stype->buttonfunc)
-				stype->buttonfunc(C, node->block, ntree, node, sock, sock->name, sock->locx+NODE_DYS, sock->locy-NODE_DYS, node->width-NODE_DY);
-		}
+		if (stype->buttonfunc)
+			stype->buttonfunc(C, node->block, ntree, node, sock, sock->name, sock->locx+NODE_DYS, sock->locy-NODE_DYS, node->width-NODE_DY);
 	}
 	
 	/* socket outputs */


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list