[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19399] branches/blender2.5/blender/source /blender: Started wrapping nodes in RNA.

Robin Allen roblovski at gmail.com
Tue Mar 24 18:40:58 CET 2009


Revision: 19399
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19399
Author:   kakbarnf
Date:     2009-03-24 18:40:58 +0100 (Tue, 24 Mar 2009)

Log Message:
-----------
Started wrapping nodes in RNA. Only shader nodes have all their options wrapped;
TEX and CMP to follow.

Also, renumbered the texture nodes because when I first wrote them I thought
they could share ID numbers with the SH and CMP nodes. D'oh!

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_node.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree_types.h

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_node.h	2009-03-24 15:45:08 UTC (rev 19398)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_node.h	2009-03-24 17:40:58 UTC (rev 19399)
@@ -388,32 +388,32 @@
 
 struct TexResult;
 
-#define TEX_NODE_OUTPUT     101
-#define TEX_NODE_CHECKER    102
-#define TEX_NODE_TEXTURE    103
-#define TEX_NODE_BRICKS     104
-#define TEX_NODE_MATH       105
-#define TEX_NODE_MIX_RGB    106
-#define TEX_NODE_RGBTOBW    107
-#define TEX_NODE_VALTORGB   108
-#define TEX_NODE_IMAGE      109
-#define TEX_NODE_CURVE_RGB  110
-#define TEX_NODE_INVERT     111
-#define TEX_NODE_HUE_SAT    112
-#define TEX_NODE_CURVE_TIME 113
-#define TEX_NODE_ROTATE     114
-#define TEX_NODE_VIEWER     115
-#define TEX_NODE_TRANSLATE  116
-#define TEX_NODE_COORD      117
-#define TEX_NODE_DISTANCE   118
-#define TEX_NODE_COMPOSE    119
-#define TEX_NODE_DECOMPOSE  120
-#define TEX_NODE_VALTONOR   121
-#define TEX_NODE_SCALE      122
+#define TEX_NODE_OUTPUT     401
+#define TEX_NODE_CHECKER    402
+#define TEX_NODE_TEXTURE    403
+#define TEX_NODE_BRICKS     404
+#define TEX_NODE_MATH       405
+#define TEX_NODE_MIX_RGB    406
+#define TEX_NODE_RGBTOBW    407
+#define TEX_NODE_VALTORGB   408
+#define TEX_NODE_IMAGE      409
+#define TEX_NODE_CURVE_RGB  410
+#define TEX_NODE_INVERT     411
+#define TEX_NODE_HUE_SAT    412
+#define TEX_NODE_CURVE_TIME 413
+#define TEX_NODE_ROTATE     414
+#define TEX_NODE_VIEWER     415
+#define TEX_NODE_TRANSLATE  416
+#define TEX_NODE_COORD      417
+#define TEX_NODE_DISTANCE   418
+#define TEX_NODE_COMPOSE    419
+#define TEX_NODE_DECOMPOSE  420
+#define TEX_NODE_VALTONOR   421
+#define TEX_NODE_SCALE      422
 
 /* 201-299 reserved. Use like this: TEX_NODE_PROC + TEX_CLOUDS, etc */
-#define TEX_NODE_PROC      200
-#define TEX_NODE_PROC_MAX  300
+#define TEX_NODE_PROC      500
+#define TEX_NODE_PROC_MAX  600
 
 extern struct ListBase node_all_textures;
 

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree.c	2009-03-24 15:45:08 UTC (rev 19398)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_nodetree.c	2009-03-24 17:40:58 UTC (rev 19399)
@@ -17,12 +17,13 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * Contributor(s): Blender Foundation (2008), Nathan Letwory
+ * Contributor(s): Blender Foundation (2008), Nathan Letwory, Robin Allen
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "RNA_define.h"
 #include "RNA_types.h"
@@ -39,11 +40,14 @@
 	bNode *node= (bNode*)ptr->data;
 
 	switch(node->type) {
-		case SH_NODE_OUTPUT:
-			return &RNA_ShaderNodeOutput;
-		case SH_NODE_MATERIAL:
-			return &RNA_ShaderNodeMaterial;
-		/* XXX complete here */
+		
+		#define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
+			case ID: return &RNA_##Category##StructName;
+				
+		#include "rna_nodetree_types.h"
+		
+		#undef DefNode
+		
 		default:
 			return &RNA_Node;
 	}
@@ -51,24 +55,298 @@
 
 #else
 
-static void rna_def_shader_node_output(BlenderRNA *brna)
+#define MaxNodes 1000
+
+enum
 {
+	Category_NoCategory,
+	Category_ShaderNode,
+	Category_CompositorNode,
+	Category_TextureNode
+};
+
+typedef struct NodeInfo
+{
+	int defined;
+	int category;
+	const char *enum_name;
+	const char *struct_name;
+	const char *base_name;
+	const char *ui_name;
+	const char *ui_desc;
+} NodeInfo;
+
+static NodeInfo nodes[MaxNodes];
+
+static void reg_node(
+	int ID, 
+	int category,
+	const char *enum_name,
+	const char *struct_name,
+	const char *base_name,
+	const char *ui_name,
+	const char *ui_desc
+){
+	NodeInfo *ni = nodes + ID;
+	
+	ni->defined = 1;
+	ni->category = category;
+	ni->enum_name = enum_name;
+	ni->struct_name = struct_name;
+	ni->base_name = base_name;
+	ni->ui_name = ui_name;
+	ni->ui_desc = ui_desc;
+}
+
+static void init(void)
+{
+	memset(nodes, 0, sizeof nodes);
+	
+	#define Str(x) #x
+	
+	#define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
+		reg_node(ID, Category_##Category, EnumName, Str(Category##StructName), #Category, UIName, UIDesc);
+		
+	#include "rna_nodetree_types.h"
+	
+	#undef DefNode
+	#undef Str
+}
+
+static StructRNA* def_node(BlenderRNA *brna, int node_id)
+{
 	StructRNA *srna;
-
-	srna= RNA_def_struct(brna, "ShaderNodeOutput", "ShaderNode");
-	RNA_def_struct_ui_text(srna, "Shader Node Output", "");
+	NodeInfo *node = nodes + node_id;
+	
+	srna= RNA_def_struct(brna, node->struct_name, node->base_name);
+	RNA_def_struct_ui_text(srna, node->ui_name, node->ui_desc);
 	RNA_def_struct_sdna(srna, "bNode");
+	
+	return srna;
 }
 
-static void rna_def_shader_node_material(BlenderRNA *brna)
+static EnumPropertyItem* alloc_node_type_items(int category)
 {
+	int i;
+	int count = 2;
+	EnumPropertyItem *item, *items;
+	
+	for(i=0; i<MaxNodes; i++)
+		if(nodes[i].defined && nodes[i].category == category)
+			count++;
+		
+	item = items = malloc(count * sizeof(EnumPropertyItem));
+	
+	for(i=0; i<MaxNodes; i++) {
+		NodeInfo *node = nodes + i;
+		if(node->defined && node->category == category) {
+			item->value = i;
+			item->identifier = node->enum_name;
+			item->name = node->ui_name;
+			item->description = node->ui_desc;
+		
+			item++;
+		}
+	}
+	
+	item->value = NODE_DYNAMIC;
+	item->identifier = "SCRIPT";
+	item->name = "Script";
+	item->description = "";
+	
+	item++;
+	
+	memset(item, 0, sizeof(EnumPropertyItem));
+	
+	return items;
+}
+
+
+/* -- Common nodes ---------------------------------------------------------- */
+
+static void def_math(BlenderRNA *brna, int id)
+{
 	StructRNA *srna;
 	PropertyRNA *prop;
+	
+	static EnumPropertyItem items[] ={
+		{ 0, "ADD",          "Add",          ""},
+		{ 1, "SUBTRACT",     "Subtract",     ""},
+		{ 2, "MULTIPLY",     "Multiply",     ""},
+		{ 3, "DIVIDE",       "Divide",       ""},
+		{ 4, "SINE",         "Sine",         ""},
+		{ 5, "COSINE",       "Cosine",       ""},
+		{ 6, "TANGENT",      "Tangent",      ""},
+		{ 7, "ARCSINE",      "Arcsine",      ""},
+		{ 8, "ARCCOSINE",    "Arccosine",    ""},
+		{ 9, "ARCTANGENT",   "Arctangent",   ""},
+		{10, "POWER",        "Power",        ""},
+		{11, "LOGARITHM",    "Logarithm",    ""},
+		{12, "MINIMUM",      "Minimum",      ""},
+		{13, "MAXIMUM",      "Maximum",      ""},
+		{14, "ROUND",        "Round",        ""},
+		{15, "LESS_THAN",    "Less Than",    ""},
+		{16, "GREATER_THAN", "Greater Than", ""},
+		
+		{0, NULL, NULL, NULL}
+	};
+	
+	srna= def_node(brna, id);
+	
+	prop= RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "custom1");
+	RNA_def_property_enum_items(prop, items);
+	RNA_def_property_ui_text(prop, "Operation", "");
+}
 
-	srna= RNA_def_struct(brna, "ShaderNodeMaterial", "ShaderNode");
-	RNA_def_struct_ui_text(srna, "Shader Node Material", "");
-	RNA_def_struct_sdna(srna, "bNode");
+static void def_vector_math(BlenderRNA *brna, int id)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	static EnumPropertyItem items[] ={
+		{0, "ADD",           "Add",           ""},
+		{1, "SUBTRACT",      "Subtract",      ""},
+		{2, "AVERAGE",       "Average",       ""},
+		{3, "DOT_PRODUCT",   "Dot Product",   ""},
+		{4, "CROSS_PRODUCT", "Cross Product", ""},
+		{5, "NORMALIZE",     "Normalize",     ""},
+		
+		{0, NULL, NULL, NULL}
+	};
+	
+	srna= def_node(brna, id);
+	
+	prop= RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "custom1");
+	RNA_def_property_enum_items(prop, items);
+	RNA_def_property_ui_text(prop, "Operation", "");
+}
 
+static void def_rgb_curve(BlenderRNA *brna, int id)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna= def_node(brna, id);
+	
+	prop= RNA_def_property(srna, "mapping", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "storage");
+	RNA_def_property_struct_type(prop, "CurveMapping");
+	RNA_def_property_ui_text(prop, "Mapping", "");
+}
+
+static void def_vector_curve(BlenderRNA *brna, int id)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna= def_node(brna, id);
+	
+	prop= RNA_def_property(srna, "mapping", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "storage");
+	RNA_def_property_struct_type(prop, "CurveMapping");
+	RNA_def_property_ui_text(prop, "Mapping", "");
+}
+
+static void def_val_to_rgb(BlenderRNA *brna, int id)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna= def_node(brna, id);
+	
+	/* TODO: uncomment when ColorBand is wrapped */
+	/*prop= RNA_def_property(srna, "color_band", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "storage");
+	RNA_def_property_struct_type(prop, "ColorBand");
+	RNA_def_property_ui_text(prop, "Color Band", "");*/
+}
+
+static void def_mix_rgb(BlenderRNA *brna, int id)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	static EnumPropertyItem blend_type_items[] ={
+		{ 0, "MIX",        "Mix",         ""},
+		{ 1, "ADD",        "Add",         ""},
+		{ 3, "SUBTRACT",   "Subtract",    ""},
+		{ 2, "MULTIPLY",   "Multiply",    ""},
+		{ 4, "SCREEN",     "Screen",      ""},
+		{ 9, "OVERLAY",    "Overlay",     ""},
+		{ 5, "DIVIDE",     "Divide",      ""},
+		{ 6, "DIFFERENCE", "Difference",  ""},
+		{ 7, "DARKEN",     "Darken",      ""},
+		{ 8, "LIGHTEN",    "Lighten",     ""},
+		{10, "DODGE",      "Dodge",       ""},
+		{11, "BURN",       "Burn",        ""},
+		{15, "COLOR",      "Color",       ""},
+		{14, "VALUE",      "Value",       ""},
+		{13, "SATURATION", "Saturation",  ""},
+		{12, "HUE",        "Hue",         ""},
+		{0, NULL, NULL, NULL}
+	};
+	
+	srna= def_node(brna, id);
+	
+	prop= RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "custom1");
+	RNA_def_property_enum_items(prop, blend_type_items);
+	RNA_def_property_ui_text(prop, "Blend Type", "");
+	
+	prop= RNA_def_property(srna, "alpha", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
+	RNA_def_property_ui_text(prop, "Diffuse", "Include alpha of second input in this operation");
+}
+
+
+/* -- Shader Node Storage Types --------------------------------------------- */
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list