[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31614] branches/particles-2010/source/ blender: Replaced the limited context type enum with RNA struct- and property pointers .

Lukas Toenne lukas.toenne at googlemail.com
Fri Aug 27 11:57:27 CEST 2010


Revision: 31614
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31614
Author:   lukastoenne
Date:     2010-08-27 11:57:27 +0200 (Fri, 27 Aug 2010)

Log Message:
-----------
Replaced the limited context type enum with RNA struct- and property pointers. This makes it possible to access any data property defined in the RNA and use it in the node tree. Must be constrained a bit later, to avoid stupid data manipulation (e.g. modifying the ui with nodes).
Implemented generic GetData/SetData nodes that can add sockets for any property in their source (as defined by the "Path" input). The nodes data type (StructRNA) must be defined in advance, because the path is only evaluated at runtime (i.e. node execution time). To make this a little more convenient, the menu could provide shortcuts to the most commonly used types, such as particles or vertices.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/blenloader/intern/readfile.c
    branches/particles-2010/source/blender/editors/space_node/drawnode.c
    branches/particles-2010/source/blender/editors/space_node/node_draw.c
    branches/particles-2010/source/blender/editors/space_node/node_edit.c
    branches/particles-2010/source/blender/editors/space_node/node_intern.h
    branches/particles-2010/source/blender/makesdna/DNA_node_types.h
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h
    branches/particles-2010/source/blender/nodes/SIM_node.h
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_add_particle.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_add_particle_force.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_debugprint.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_filter.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_object_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_particle_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_vertex_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_if.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_particle_dynamics.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_pass.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_random.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_object_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_particle_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_vertex_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_subprogram.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_timestep.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_vector_compose.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_vector_decompose.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_vectormath.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.h
    branches/particles-2010/source/blender/nodes/intern/node_tree_composite.c
    branches/particles-2010/source/blender/nodes/intern/node_tree_shader.c
    branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c
    branches/particles-2010/source/blender/nodes/intern/node_tree_texture.c

Added Paths:
-----------
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_data.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-08-27 08:21:11 UTC (rev 31613)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-08-27 09:57:27 UTC (rev 31614)
@@ -53,6 +53,7 @@
 struct Main;
 struct MTex;
 struct PointerRNA;
+struct PropertyRNA;
 struct rctf;
 struct RenderData;
 struct Scene;
@@ -70,7 +71,6 @@
 	char *name;
 	float val1, val2, val3, val4;	/* default alloc value for inputs */
 	float min, max;					/* default range for inputs */
-	int contexttype;
 } bNodeSocketType;
 
 typedef struct bNodeType {
@@ -101,6 +101,9 @@
 	/* gpu */
 	int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
 
+	/* called when the node is updated (e.g. linked) in the editor. */
+	void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
+
 	/* simulation nodes */
 	int (*sim_execfunc)(struct SimNodeThreadContext *ctx, struct SimNodeJob *job);
 	int (*sim_opexecfunc)(struct SimNodeThreadContext *ctx, struct bNode *node, int level, int *r_opsock);
@@ -153,6 +156,11 @@
 	void (*beginExec)(struct bNodeTree *ntree);
 	void (*endExec)(struct bNodeTree *ntree);
 	void (*exec)(struct bNodeTree *ntree, void *callerdata, int thread);
+
+	/* called when a node is updated (e.g. linked) in the editor.
+	 * individual node update calls should be made internally if this function is defined! */
+	void (*updateNode)(struct bNodeTree *ntree, struct bNode *node);
+
 	int (*compatibleSocketTypes)(int type_a, int type_b);
 	int (*preferredSocketType)(int type_a, int type_b);
 } bNodeTreeTypeInfo;
@@ -178,7 +186,6 @@
 void			ntreeUpdateTree(struct bNodeTree *ntree);
 void			ntreeUpdateGroupTree(struct bNodeTree *ntree, struct bNodeTree *group);
 void			ntreeUpdateFullTree(struct bNodeTree *ntree);
-void			ntreeUpdateListSockets(struct bNodeTree *ntree);
 
 void			ntreeCalcSocketTypeIslands(struct bNodeTree *ntree);
 void			ntreeFreeSocketTypeIslands(struct bNodeTree *ntree);
@@ -211,12 +218,13 @@
 
 void			nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node);
 void			nodeUniqueName(struct bNodeTree *ntree, struct bNode *node);
-struct bNodeSocket *nodeAddInputSocket(struct bNode *node, char *name, int type, float *default_value, float min, float max);
-struct bNodeSocket *nodeAddOutputSocket(struct bNode *node, char *name, int type, float *default_value, float min, float max);
-struct bNodeSocket *nodeInsertInputSocket(struct bNode *node, struct bNodeSocket *next_sock, char *name, int type, float *default_value, float min, float max);
-struct bNodeSocket *nodeInsertOutputSocket(struct bNode *node, struct bNodeSocket *next_sock, char *name, int type, float *default_value, float min, float max);
+struct bNodeSocket *nodeAddInputSocket(struct bNode *node, const char *name, int type, float *default_value, float min, float max);
+struct bNodeSocket *nodeAddOutputSocket(struct bNode *node, const char *name, int type, float *default_value, float min, float max);
+struct bNodeSocket *nodeInsertInputSocket(struct bNode *node, struct bNodeSocket *next_sock, const char *name, int type, float *default_value, float min, float max);
+struct bNodeSocket *nodeInsertOutputSocket(struct bNode *node, struct bNodeSocket *next_sock, const char *name, int type, float *default_value, float min, float max);
 void			nodeRemoveInputSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock);
 void			nodeRemoveOutputSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock);
+void			nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node);
 void			nodeAddSocketsFromType(struct bNode *node, struct bNodeType *ntype);
 struct bNode	*nodeAddNodeType(struct bNodeTree *ntree, int type, struct bNodeTree *ngroup, struct ID *id);
 void			nodeRegisterType(struct ListBase *typelist, const struct bNodeType *ntype) ;
@@ -528,17 +536,19 @@
 #define SIM_NODE_CROSSPRODUCT		704
 
 /* data input/output */
-#define SIM_NODE_TIMESTEP			750
-#define SIM_NODE_GETOBJECTDATA		751
-#define SIM_NODE_SETOBJECTDATA		752
-#define SIM_NODE_GETVERTEXDATA		753
-#define SIM_NODE_SETVERTEXDATA		754
-#define SIM_NODE_ADDPARTICLE		755
-#define SIM_NODE_GETPARTICLEDATA	756
-#define SIM_NODE_SETPARTICLEDATA	757
-#define SIM_NODE_RANDOM				758
-#define SIM_NODE_PARTICLEDYNAMICS	759
-#define SIM_NODE_ADDPARTICLEFORCE	760
+#define SIM_NODE_GETDATA			750
+#define SIM_NODE_SETDATA			751
+#define SIM_NODE_TIMESTEP			760
+#define SIM_NODE_GETOBJECTDATA		761
+#define SIM_NODE_SETOBJECTDATA		762
+#define SIM_NODE_GETVERTEXDATA		763
+#define SIM_NODE_SETVERTEXDATA		764
+#define SIM_NODE_ADDPARTICLE		765
+#define SIM_NODE_GETPARTICLEDATA	766
+#define SIM_NODE_SETPARTICLEDATA	767
+#define SIM_NODE_RANDOM				768
+#define SIM_NODE_PARTICLEDYNAMICS	769
+#define SIM_NODE_ADDPARTICLEFORCE	770
 
 /* TO BE REMOVED: debugging stuff, testing, etc. */
 #define SIM_NODE_DEBUGPRINT			801
@@ -546,6 +556,11 @@
 /* API */
 void ntreeSimulationExecTree(struct SimulationContext *sim);
 
+void sim_node_update_datatype(struct bNodeTree *ntree, struct bNode *node);
+struct StructRNA *sim_node_get_datatype(struct bNode *node);
+void sim_node_add_rna_socket(struct bNode *node, struct PropertyRNA *prop);
+int sim_node_convert_rna_property(struct PropertyRNA *prop);
+
 /**/
 
 void init_nodesystem(void);

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-08-27 08:21:11 UTC (rev 31613)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-08-27 09:57:27 UTC (rev 31614)
@@ -135,16 +135,20 @@
 	ntree->init |= NTREE_TYPE_INIT;
 }
 
-static bNodeSocket *make_socket(int is_input, char *name, int type, float *default_value, float min, float max)
+static bNodeSocket *make_socket(int is_input, const char *name, int type, float *default_value, float min, float max)
 {
 	bNodeSocket *sock= MEM_callocN(sizeof(bNodeSocket), "sock");
 	
 	BLI_strncpy(sock->name, name, NODE_MAXSTR);
 	sock->limit = (is_input ? 1 : 0xFFF);
 	sock->type= type;
-	sock->context.type = NDC_UNDEFINED;
-	sock->context.source = NULL;
+	sock->context.prop = NULL;
+	sock->context.id = NULL;
+	sock->context.data = NULL;
 	sock->intern = 1;
+	if (type == SOCK_ANY)
+		sock->flag |= SOCK_ADAPT_TYPE;
+	sock->flag |= SOCK_ADAPT_CONTEXT;
 	
 	sock->to_index= 0;
 	sock->tonode= NULL;
@@ -160,26 +164,26 @@
 	return sock;
 }
 
-bNodeSocket *nodeAddInputSocket(bNode *node, char *name, int type, float *default_value, float min, float max)
+bNodeSocket *nodeAddInputSocket(bNode *node, const char *name, int type, float *default_value, float min, float max)
 {
 	bNodeSocket *sock = make_socket(1, name, type, default_value, min, max);
 	BLI_addtail(&node->inputs, sock);
 	return sock;
 }
-bNodeSocket *nodeAddOutputSocket(bNode *node, char *name, int type, float *default_value, float min, float max)
+bNodeSocket *nodeAddOutputSocket(bNode *node, const char *name, int type, float *default_value, float min, float max)
 {
 	bNodeSocket *sock = make_socket(0, name, type, default_value, min, max);
 	BLI_addtail(&node->outputs, sock);
 	return sock;
 }
 
-bNodeSocket *nodeInsertInputSocket(bNode *node, bNodeSocket *next_sock, char *name, int type, float *default_value, float min, float max)
+bNodeSocket *nodeInsertInputSocket(bNode *node, bNodeSocket *next_sock, const char *name, int type, float *default_value, float min, float max)
 {
 	bNodeSocket *sock = make_socket(1, name, type, default_value, min, max);
 	BLI_insertlinkbefore(&node->inputs, next_sock, sock);
 	return sock;
 }
-bNodeSocket *nodeInsertOutputSocket(bNode *node, bNodeSocket *next_sock, char *name, int type, float *default_value, float min, float max)
+bNodeSocket *nodeInsertOutputSocket(bNode *node, bNodeSocket *next_sock, const char *name, int type, float *default_value, float min, float max)
 {
 	bNodeSocket *sock = make_socket(0, name, type, default_value, min, max);
 	BLI_insertlinkbefore(&node->outputs, next_sock, sock);
@@ -214,6 +218,20 @@
 	BLI_remlink(&node->outputs, sock);
 	MEM_freeN(sock);
 }
+void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node)
+{
+	bNodeLink *link, *next;
+	
+	for(link= ntree->links.first; link; link= next) {
+		next= link->next;
+		if(link->fromnode==node || link->tonode==node) {
+			nodeRemLink(ntree, link);
+		}
+	}
+	
+	BLI_freelistN(&node->inputs);
+	BLI_freelistN(&node->outputs);
+}
 
 /* ************** Group stuff ********** */
 
@@ -749,10 +767,6 @@
 			default_value[2] = stype->val3;
 			default_value[3] = stype->val4;
 			sock = nodeAddInputSocket(node, stype->name, stype->type, default_value, stype->min, stype->max);
-			if (stype->type == SOCK_ANY)
-				sock->flag |= SOCK_ADAPT_TYPE;
-			if (stype->contexttype == NDC_UNDEFINED)
-				sock->flag |= SOCK_ADAPT_CONTEXT;
 			stype++;
 		}
 	}
@@ -764,10 +778,6 @@
 			default_value[2] = stype->val3;
 			default_value[3] = stype->val4;
 			sock = nodeAddOutputSocket(node, stype->name, stype->type, default_value, stype->min, stype->max);
-			if (stype->type == SOCK_ANY)
-				sock->flag |= SOCK_ADAPT_TYPE;
-			if (stype->contexttype == NDC_UNDEFINED)
-				sock->flag |= SOCK_ADAPT_CONTEXT;
 			stype++;
 		}
 	}
@@ -1487,7 +1497,7 @@
 static int set_update_flag_recursive(bNodeTree *ntree)
 {
 	bNode *node;
-	int update;
+	int update = 0;
 	
 	for (node=ntree->nodes.first; node; node = node->next)
 		if (node->type == NODE_GROUP && node->id)
@@ -1613,45 +1623,6 @@
 	}
 }
 
-void ntreeUpdateListSockets(bNodeTree *ntree)
-{
-	#if 0
-	bNode *node;
-	bNodeSocketType *stype;
-	bNodeSocket *sock, *next_sock;
-	
-	/* nodes are presumed fully verified, stype and socket list are in sync */
-	for (node=ntree->nodes.first; node; node = node->next) {
-		stype= node->typeinfo->inputs;
-		sock= node->inputs.first;
-		while (sock) {
-			if (stype->flag & SOCK_LIST) {
-				/* step through all sockets of this type (i.e. the list) */
-				while (sock && sock->stype == stype) {
-					if (!sock->link) {
-						next_sock = sock->next;
-						node_rem_socket(ntree, &node->inputs, sock);
-						sock = next_sock;
-					}
-					else {
-						sock = sock->next;
-					}
-				}
-				/* add an unlinked last socket, so the list can be extended */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list