[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32749] branches/particles-2010/source/ blender/nodes/intern/simulation/nodes: * Random node is back up.

Lukas Toenne lukas.toenne at googlemail.com
Thu Oct 28 10:48:28 CEST 2010


Revision: 32749
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32749
Author:   lukastoenne
Date:     2010-10-28 10:48:28 +0200 (Thu, 28 Oct 2010)

Log Message:
-----------
* Random node is back up. This now has a separate input for the element ID to avoid adding this to a seed value by hand. Possibly needs some work still to make a thread-safe version!
* Fixed bug in divide node for vectors
* Fixed RNA property search, this now uses the socket name instead of the identifier. Might cause trouble with duplicate RNA property ui names, but those would need to be fixed anyway.

Modified Paths:
--------------
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_random.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c	2010-10-28 07:11:19 UTC (rev 32748)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c	2010-10-28 08:48:28 UTC (rev 32749)
@@ -60,7 +60,7 @@
 	return 1;
 }
 
-static PropertyRNA *find_rna_property(bNode *node, const char *identifier)
+static PropertyRNA *find_rna_property(bNode *node, const char *name)
 {
 	SimDataNode *data= (SimDataNode*)node->storage;
 //	SimDataContext ctx;
@@ -78,7 +78,7 @@
 			prop = (PropertyRNA *)link;
 			if (!rna_property_valid(node, prop))
 				continue;
-			if (strcmp(identifier, RNA_property_identifier(prop))==0)
+			if (strcmp(name, RNA_property_ui_name(prop))==0)
 				return prop;
 		}
 		

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c	2010-10-28 07:11:19 UTC (rev 32748)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c	2010-10-28 08:48:28 UTC (rev 32749)
@@ -410,9 +410,9 @@
 }
 static void kernel_divide_vector(int global_id, void **args, SimNodeStack *node)
 {
-	float *res=SIM_OUTPUT_RGBA(0, global_id);
-	const float *a=SIM_INPUT_RGBA(0, global_id);
-	const float *b=SIM_INPUT_RGBA(1, global_id);
+	float *res=SIM_OUTPUT_VECTOR(0, global_id);
+	const float *a=SIM_INPUT_VECTOR(0, global_id);
+	const float *b=SIM_INPUT_VECTOR(1, global_id);
 	res[0] = (b[0] != 0.0f ? a[0] / b[0] : 0.0f);
 	res[1] = (b[1] != 0.0f ? a[1] / b[1] : 0.0f);
 	res[2] = (b[2] != 0.0f ? a[2] / b[2] : 0.0f);

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_random.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_random.c	2010-10-28 07:11:19 UTC (rev 32748)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_random.c	2010-10-28 08:48:28 UTC (rev 32749)
@@ -33,7 +33,8 @@
 /* **************** Random number generator  ******************** */
 
 static bNodeSocketDefinition inputs[]= { 
-	{ SOCK_INT, 1, "Seed", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f },
+	{ SOCK_INT, 1, "Seed", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f },
+	{ SOCK_INT, 1, "ID", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000000.0f },
 	{ -1, 0, "" }
 };
 
@@ -42,6 +43,35 @@
 	{ -1, 0, "" }
 };
 
+static char *generate_source(struct SimNodeStack *node)
+{
+	DynStr *source= sim_kernel_source_begin(node, NULL, 0, NULL);
+	/* TODO no native opencl rng yet, would have to implement something by hand */
+	BLI_dynstr_append(source, STRINGIFY(
+		*OUTPUT0_FLOAT(get_global_id(0)) = 0.0f;
+		));
+	return sim_kernel_source_end(source);
+}
+static void kernel_random(int global_id, void **args, SimNodeStack *node)
+{
+	unsigned int offset = SIM_INPUT_FLOAT(1, global_id) + 123456;
+	offset *= offset;
+	BLI_srandom(SIM_INPUT_INT(0, global_id) + offset);
+	/* TODO this is probably NOT threadsafe!! */
+	*SIM_OUTPUT_FLOAT(0, global_id) = BLI_frand();
+}
+
+static void enqueue(SimExecData *execdata, SimNodeStack *node, SimDataContext *self)
+{
+	SimKernel *kernel;
+	char kernelname[64];
+	
+	sim_kernel_source_name(node, NULL, kernelname);
+	kernel=MEM_callocN(sizeof(SimKernel), "SimKernel");
+	sim_kernel_init(execdata, kernel, node, kernel_random, kernelname, 0);
+	sim_kernel_enqueue(execdata, kernel, node->outstack[0].context.size, &node->inputevents, &node->events);
+}
+
 void nodeRegisterSimRandom(ListBase *typelist)
 {
 	static bNodeType type;
@@ -59,7 +89,9 @@
 //	type.flag = NODE_OPTIONS;
 	type.inputs = inputs;
 	type.outputs = outputs;
-//	type.enqueue = enqueue;
 	
+	type.generate_source = generate_source;
+	type.enqueue = enqueue;
+	
 	nodeRegisterType(typelist, &type);
 }

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c	2010-10-28 07:11:19 UTC (rev 32748)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c	2010-10-28 08:48:28 UTC (rev 32749)
@@ -65,7 +65,7 @@
 	return 1;
 }
 
-static PropertyRNA *find_rna_property(bNode *node, const char *identifier)
+static PropertyRNA *find_rna_property(bNode *node, const char *name)
 {
 	SimDataNode *data= (SimDataNode*)node->storage;
 //	SimDataContext ctx;
@@ -83,7 +83,7 @@
 			prop = (PropertyRNA *)link;
 			if (!rna_property_valid(node, prop))
 				continue;
-			if (strcmp(identifier, RNA_property_identifier(prop))==0)
+			if (strcmp(name, RNA_property_ui_name(prop))==0)
 				return prop;
 		}
 	}





More information about the Bf-blender-cvs mailing list