[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33152] branches/particles-2010/source/ blender: Adaptable nodes get a limiting type set.

Lukas Toenne lukas.toenne at googlemail.com
Thu Nov 18 09:03:07 CET 2010


Revision: 33152
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33152
Author:   lukastoenne
Date:     2010-11-18 09:03:07 +0100 (Thu, 18 Nov 2010)

Log Message:
-----------
Adaptable nodes get a limiting type set. This prevents the user from linking invalid socket types to nodes that cannot use them. Currently only used by math nodes (e.g. it is not possible any more to link operator sockets to "Add").

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenlib/BLI_math_matrix.h
    branches/particles-2010/source/blender/blenlib/intern/math_matrix.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-11-18 05:45:21 UTC (rev 33151)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-11-18 08:03:07 UTC (rev 33152)
@@ -127,7 +127,10 @@
 
 	/* called when the node is updated (e.g. linked) in the editor. */
 	void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
+	/* called when adaptable socket has been changed and types should be resolved */
 	void (*adaptSocketTypes)(struct bNodeTree *ntree, struct bNode *node);
+	/* list of types the node can adapt (if no custom function is used) */
+	int *adapt_types;
 
 	char socketstoragename[64];		/* socket storage struct name for DNA */
 	void (*initsocketfunc)(struct bNodeSocket *sock);

Modified: branches/particles-2010/source/blender/blenlib/BLI_math_matrix.h
===================================================================
--- branches/particles-2010/source/blender/blenlib/BLI_math_matrix.h	2010-11-18 05:45:21 UTC (rev 33151)
+++ branches/particles-2010/source/blender/blenlib/BLI_math_matrix.h	2010-11-18 08:03:07 UTC (rev 33152)
@@ -62,6 +62,9 @@
 void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
 void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
 
+void sub_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
+void sub_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
+
 void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
 void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
 void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);

Modified: branches/particles-2010/source/blender/blenlib/intern/math_matrix.c
===================================================================
--- branches/particles-2010/source/blender/blenlib/intern/math_matrix.c	2010-11-18 05:45:21 UTC (rev 33151)
+++ branches/particles-2010/source/blender/blenlib/intern/math_matrix.c	2010-11-18 08:03:07 UTC (rev 33152)
@@ -434,6 +434,24 @@
 			m1[i][j]= m2[i][j] + m3[i][j];
 }
 
+void sub_m3_m3m3(float m1[][3], float m2[][3], float m3[][3])
+{
+	int i, j;
+
+	for(i=0;i<3;i++)
+		for(j=0;j<3;j++)
+			m1[i][j]= m2[i][j] - m3[i][j];
+}
+
+void sub_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
+{
+	int i, j;
+
+	for(i=0;i<4;i++)
+		for(j=0;j<4;j++)
+			m1[i][j]= m2[i][j] - m3[i][j];
+}
+
 int invert_m3(float m[3][3])
 {
 	float tmp[3][3];

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c	2010-11-18 05:45:21 UTC (rev 33151)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c	2010-11-18 08:03:07 UTC (rev 33152)
@@ -120,6 +120,20 @@
 	SIM_INPUT_VECTOR(1, global_id, b);
 	add_v3_v3v3(SIM_OUTPUT_VECTOR(0, global_id), a, b);
 }
+static void kernel_add_quat(int global_id, void **UNUSED(args), SimNodeStack *node)
+{
+	float a[4], b[4];
+	SIM_INPUT_QUAT(0, global_id, a);
+	SIM_INPUT_QUAT(1, global_id, b);
+	add_qt_qtqt(SIM_OUTPUT_QUAT(0, global_id), a, b, 1.0f);
+}
+static void kernel_add_matrix(int global_id, void **UNUSED(args), SimNodeStack *node)
+{
+	float a[4][4], b[4][4];
+	SIM_INPUT_MATRIX(0, global_id, a);
+	SIM_INPUT_MATRIX(1, global_id, b);
+	add_m4_m4m4(SIM_OUTPUT_MATRIX(0, global_id), a, b);
+}
 
 static void enqueue_add(SimExecData *execdata, SimNodeStack *node, SimDataContext *self)
 {
@@ -132,6 +146,8 @@
 	case SOCK_FLOAT:	kernelfunc= kernel_add_float;	break;
 	case SOCK_INT:		kernelfunc= kernel_add_int;		break;
 	case SOCK_VECTOR:	kernelfunc= kernel_add_vector;	break;
+	case SOCK_QUAT:		kernelfunc= kernel_add_quat;	break;
+	case SOCK_MATRIX:	kernelfunc= kernel_add_matrix;	break;
 	default:			kernelfunc= NULL;
 	}
 	
@@ -145,6 +161,7 @@
 void nodeRegisterSimAdd(ListBase *typelist)
 {
 	static bNodeType type;
+	static int adapt_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_VECTOR, SOCK_QUAT, SOCK_MATRIX, -1 };
 	memset(&type, 0, sizeof(bNodeType));
 	
 	/* required */
@@ -159,6 +176,7 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs_binary_any;
 	type.outputs = outputs_any;
+	type.adapt_types = adapt_types;
 	type.generate_source = generate_source_add;
 	type.enqueue = enqueue_add;
 	
@@ -210,6 +228,21 @@
 	SIM_INPUT_VECTOR(1, global_id, b);
 	sub_v3_v3v3(SIM_OUTPUT_VECTOR(0, global_id), a, b);
 }
+static void kernel_subtract_quat(int global_id, void **UNUSED(args), SimNodeStack *node)
+{
+	float a[4], b[4];
+	SIM_INPUT_QUAT(0, global_id, a);
+	SIM_INPUT_QUAT(1, global_id, b);
+	sub_qt_qtqt(SIM_OUTPUT_QUAT(0, global_id), a, b);
+}
+static void kernel_subtract_matrix(int global_id, void **UNUSED(args), SimNodeStack *node)
+{
+	float a[4][4], b[4][4];
+	SIM_INPUT_MATRIX(0, global_id, a);
+	SIM_INPUT_MATRIX(1, global_id, b);
+	
+	sub_m4_m4m4(SIM_OUTPUT_MATRIX(0, global_id), a, b);
+}
 
 static void enqueue_subtract(SimExecData *execdata, SimNodeStack *node, SimDataContext *self)
 {
@@ -222,6 +255,8 @@
 	case SOCK_FLOAT:	kernelfunc= kernel_subtract_float;	break;
 	case SOCK_INT:		kernelfunc= kernel_subtract_int;		break;
 	case SOCK_VECTOR:	kernelfunc= kernel_subtract_vector;	break;
+	case SOCK_QUAT:		kernelfunc= kernel_subtract_quat;	break;
+	case SOCK_MATRIX:	kernelfunc= kernel_subtract_matrix;	break;
 	default:			kernelfunc= NULL;
 	}
 	
@@ -235,6 +270,7 @@
 void nodeRegisterSimSubtract(ListBase *typelist)
 {
 	static bNodeType type;
+	static int adapt_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_VECTOR, SOCK_QUAT, SOCK_MATRIX, -1 };
 	memset(&type, 0, sizeof(bNodeType));
 	
 	/* required */
@@ -249,6 +285,7 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs_binary_any;
 	type.outputs = outputs_any;
+	type.adapt_types = adapt_types;
 	type.generate_source = generate_source_subtract;
 	type.enqueue = enqueue_subtract;
 	
@@ -300,6 +337,21 @@
 	SIM_INPUT_VECTOR(1, global_id, b);
 	mul_v3_v3v3(SIM_OUTPUT_VECTOR(0, global_id), a, b);
 }
+static void kernel_multiply_quat(int global_id, void **UNUSED(args), SimNodeStack *node)
+{
+	float a[4], b[4];
+	SIM_INPUT_QUAT(0, global_id, a);
+	SIM_INPUT_QUAT(1, global_id, b);
+	mul_qt_qtqt(SIM_OUTPUT_QUAT(0, global_id), a, b);
+}
+static void kernel_multiply_matrix(int global_id, void **UNUSED(args), SimNodeStack *node)
+{
+	float a[4][4], b[4][4];
+	SIM_INPUT_MATRIX(0, global_id, a);
+	SIM_INPUT_MATRIX(1, global_id, b);
+	
+	mul_m4_m4m4(SIM_OUTPUT_MATRIX(0, global_id), a, b);
+}
 
 static void enqueue_multiply(SimExecData *execdata, SimNodeStack *node, SimDataContext *self)
 {
@@ -312,6 +364,8 @@
 	case SOCK_FLOAT:	kernelfunc= kernel_multiply_float;	break;
 	case SOCK_INT:		kernelfunc= kernel_multiply_int;		break;
 	case SOCK_VECTOR:	kernelfunc= kernel_multiply_vector;	break;
+	case SOCK_QUAT:		kernelfunc= kernel_multiply_quat;	break;
+	case SOCK_MATRIX:	kernelfunc= kernel_multiply_matrix;	break;
 	default:			kernelfunc= NULL;
 	}
 	
@@ -325,6 +379,7 @@
 void nodeRegisterSimMultiply(ListBase *typelist)
 {
 	static bNodeType type;
+	static int adapt_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_VECTOR, SOCK_QUAT, SOCK_MATRIX, -1 };
 	memset(&type, 0, sizeof(bNodeType));
 	
 	/* required */
@@ -339,6 +394,7 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs_binary_any;
 	type.outputs = outputs_any;
+	type.adapt_types = adapt_types;
 	type.generate_source = generate_source_multiply;
 	type.enqueue = enqueue_multiply;
 	
@@ -420,6 +476,7 @@
 void nodeRegisterSimDivide(ListBase *typelist)
 {
 	static bNodeType type;
+	static int adapt_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_VECTOR, -1 };
 	memset(&type, 0, sizeof(bNodeType));
 	
 	/* required */
@@ -434,6 +491,7 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs_binary_any;
 	type.outputs = outputs_any;
+	type.adapt_types = adapt_types;
 	type.generate_source = generate_source_divide;
 	type.enqueue = enqueue_divide;
 	
@@ -920,6 +978,7 @@
 void nodeRegisterSimMinimum(ListBase *typelist)
 {
 	static bNodeType type;
+	static int adapt_types[] = { SOCK_FLOAT, SOCK_INT, -1 };
 	memset(&type, 0, sizeof(bNodeType));
 	
 	/* required */
@@ -934,6 +993,7 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs_binary_any;
 	type.outputs = outputs_any;
+	type.adapt_types = adapt_types;
 	type.generate_source = generate_source_minimum;
 	type.enqueue = enqueue_minimum;
 	
@@ -1001,6 +1061,7 @@
 void nodeRegisterSimMaximum(ListBase *typelist)
 {
 	static bNodeType type;
+	static int adapt_types[] = { SOCK_FLOAT, SOCK_INT, -1 };
 	memset(&type, 0, sizeof(bNodeType));
 	
 	/* required */
@@ -1015,6 +1076,7 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs_binary_any;
 	type.outputs = outputs_any;
+	type.adapt_types = adapt_types;
 	type.generate_source = generate_source_maximum;
 	type.enqueue = enqueue_maximum;
 	

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c	2010-11-18 05:45:21 UTC (rev 33151)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodetree.c	2010-11-18 08:03:07 UTC (rev 33152)
@@ -102,6 +102,19 @@
 	return 0;
 }
 
+static int node_supports_type(bNode *node, int type)
+{
+	if (node->typeinfo->adapt_types) {
+		int *at;
+		for (at=node->typeinfo->adapt_types; *at >= 0; ++at)
+			if (*at == type)
+				return 1;
+		return 0;
+	}
+	else
+		return 1;
+}
+
 /* standard method of adapting socket types in a node:
  * -find the best type from input sockets
  * -if input sockets did not resolve types, look among outputs
@@ -120,7 +133,7 @@
 //			if (!socket_types_compatible(sock->restype, restype))
 //				restype = -1;
 //			else
-			if (socket_type_priority(sock->restype) > socket_type_priority(restype))
+			if (node_supports_type(node, sock->restype) && socket_type_priority(sock->restype) > socket_type_priority(restype))
 				restype = sock->restype;
 			if (sock->resolved)
 				resolved = 1;
@@ -133,7 +146,7 @@
 //				if (!socket_types_compatible(sock->restype, restype))
 //					restype = -1;
 //				else
-				if (socket_type_priority(sock->restype) > socket_type_priority(restype))
+				if (node_supports_type(node, sock->restype) && socket_type_priority(sock->restype) > socket_type_priority(restype))
 					restype = sock->restype;
 //				if (sock->resolved)		/* never happens */
 //					resolved = 1;
@@ -255,7 +268,7 @@
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list