[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32444] branches/particles-2010/source/ blender: Added a ForGroup node type.

Lukas Toenne lukas.toenne at googlemail.com
Wed Oct 13 12:02:50 CEST 2010


Revision: 32444
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32444
Author:   lukastoenne
Date:     2010-10-13 12:02:50 +0200 (Wed, 13 Oct 2010)

Log Message:
-----------
Added a ForGroup node type. This is a special loop node that takes an input path (like data nodes), which needs to point to an object group. The input operator is then executed for each object in the group, using that object as the "self" context, so each object in the group can be modified by a subtree in the same way.

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/makesrna/intern/rna_nodetree_types.h
    branches/particles-2010/source/blender/nodes/SIM_node.h
    branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h

Added Paths:
-----------
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_for_group.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-13 07:57:59 UTC (rev 32443)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-13 10:02:50 UTC (rev 32444)
@@ -544,6 +544,7 @@
 #define SIM_NODE_FOR				605
 #define SIM_NODE_WHILE				606
 #define SIM_NODE_FILTER				607
+#define SIM_NODE_FOR_GROUP			608
 
 /* scalar math */
 #define SIM_NODE_ADD				650

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-10-13 07:57:59 UTC (rev 32443)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-10-13 10:02:50 UTC (rev 32444)
@@ -2360,6 +2360,7 @@
 	nodeRegisterType(ntypelist, &sim_node_for);
 	nodeRegisterType(ntypelist, &sim_node_while);
 	nodeRegisterType(ntypelist, &sim_node_filter);
+	nodeRegisterType(ntypelist, &sim_node_for_group);
 
 	nodeRegisterType(ntypelist, &sim_node_add);
 	nodeRegisterType(ntypelist, &sim_node_subtract);

Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h	2010-10-13 07:57:59 UTC (rev 32443)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h	2010-10-13 10:02:50 UTC (rev 32444)
@@ -140,6 +140,7 @@
 DefNode( SimulationNode, SIM_NODE_FOR,            0,                      "FOR",            For,              "For",               ""              )
 DefNode( SimulationNode, SIM_NODE_WHILE,          def_sim_while,          "WHILE",          While,            "While",             ""              )
 DefNode( SimulationNode, SIM_NODE_FILTER,         0,                      "FILTER",         Filter,           "Filter",            ""              )
+DefNode( SimulationNode, SIM_NODE_FOR_GROUP,      0,                      "FORGROUP",       ForGroup,         "ForGroup",          ""              )
 DefNode( SimulationNode, SIM_NODE_ADD,            0,                      "ADD",            Add,              "Add",               ""              )
 DefNode( SimulationNode, SIM_NODE_SUBTRACT,       0,                      "SUBTRACT",       Subtract,         "Subtract",          ""              )
 DefNode( SimulationNode, SIM_NODE_MULTIPLY,       0,                      "MULTIPLY",       Multiply,         "Multiply",          ""              )

Modified: branches/particles-2010/source/blender/nodes/SIM_node.h
===================================================================
--- branches/particles-2010/source/blender/nodes/SIM_node.h	2010-10-13 07:57:59 UTC (rev 32443)
+++ branches/particles-2010/source/blender/nodes/SIM_node.h	2010-10-13 10:02:50 UTC (rev 32444)
@@ -46,6 +46,7 @@
 extern bNodeType sim_node_for;
 extern bNodeType sim_node_while;
 extern bNodeType sim_node_filter;
+extern bNodeType sim_node_for_group;
 
 extern bNodeType sim_node_add;
 extern bNodeType sim_node_subtract;

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h	2010-10-13 07:57:59 UTC (rev 32443)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h	2010-10-13 10:02:50 UTC (rev 32444)
@@ -125,9 +125,11 @@
 
 struct SimNodeStack;
 typedef struct SimSocketStack {
+	SimDataContext context;
+	
+	/* constants */
 	bNodeSocket *base;
 	struct SimNodeStack *node;
-	SimDataContext context;
 	int type;
 	int users;
 	
@@ -145,16 +147,18 @@
 	struct SimSocketStack **instack;
 	struct SimSocketStack *outstack;
 	int totin, totout;
-	int totusers, totfinished;		/* total output users, finished users */
+	int totusers, totfinished;			/* total output users, finished users */
 	
-	ListBase events;
-	ListBase inputevents;
+	ListBase events;					/* finishing events */
+	ListBase inputevents;				/* merged list of all input node events */
+	
+	void *opstorage;					/* storage for operator execution */
 } SimNodeStack;
 
 typedef struct SimNodeOperator {
 	struct SimNodeOperator *next, *prev;
 	struct SimNodeStack *node;
-	int resume_level;		/* execution level on resume */
+	int resume_level;				/* execution level on resume */
 	SimDataContext self;
 } SimNodeOperator;
 

Added: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_for_group.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_for_group.c	                        (rev 0)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_for_group.c	2010-10-13 10:02:50 UTC (rev 32444)
@@ -0,0 +1,128 @@
+/**
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version. 
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+* 
+* The Original Code is Copyright (C) 2006 Blender Foundation.
+* All rights reserved.
+* 
+* The Original Code is: all of this file.
+* 
+* Contributor(s): none yet.
+* 
+* ***** END GPL LICENSE BLOCK *****
+
+*/
+
+#include "../SIM_util.h"
+
+#include "RNA_access.h"
+
+/* **************** Execute for each object in a group ******************** */
+
+static bNodeSocketType inputs[]= { 
+	{ SOCK_STRING, 1, "Path", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
+	{ SOCK_OP, 1, "Op", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
+	{ -1, 0, "" }
+};
+
+static bNodeSocketType outputs[]= { 
+	{ SOCK_OP, 0, "Exec", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
+	{ -1, 0, "" }
+};
+
+typedef struct ForGroupStorage {
+	int totob;
+	struct PointerRNA *obptr;
+} ForGroupStorage;
+
+static void enqueue_op(SimExecData *execdata, SimNodeStack *node, SimDataContext *self, int execlevel, int *pushop)
+{
+	char path[SIM_STRINGLENGTH];
+	SimDataContext ctx;
+	SimSocketIterator sockiter;
+	int resolved;
+	
+	/* prepare the node instance on first operator call */
+	if (execlevel == 0) {
+		sim_input_begin(execdata, node->instack[0], &sockiter);
+		sim_input_read_string(execdata, &sockiter, path);
+		sim_input_end(execdata, &sockiter);
+		if (execdata->error) return;
+		
+		/* resolve the context */
+		resolved = sim_context_path_resolve(self, path, &ctx);
+		if (resolved && RNA_struct_is_a(sim_context_type(&ctx), &RNA_Group)) {
+			ForGroupStorage *storage;
+			CollectionPropertyIterator colliter;
+			int i;
+			
+			node->opstorage = storage = MEM_callocN(sizeof(ForGroupStorage), "ForGroupStorage");
+			
+			/* make a local copy of group objects collection (in case it is modified during execution) */
+			storage->totob = RNA_collection_length(&ctx.ptr, "objects");
+			storage->obptr = MEM_callocN(storage->totob*sizeof(PointerRNA), "ForGroup object pointers");
+			
+			RNA_collection_begin(&ctx.ptr, "objects", &colliter);
+			i=0;
+			while (colliter.valid) {
+				storage->obptr[i] = colliter.ptr;
+				RNA_property_collection_next(&colliter);
+				++i;
+			}
+			RNA_property_collection_end(&colliter);
+		}
+	}
+	
+	if (node->opstorage) {
+		ForGroupStorage *storage = (ForGroupStorage*)node->opstorage;
+		if (execlevel < storage->totob) {
+			*pushop = 1;
+			sim_context_create(self->scene, &storage->obptr[execlevel], NULL, 0, self);
+		}
+		else {
+			MEM_freeN(storage->obptr);
+			MEM_freeN(storage);
+		}
+	}
+}
+
+bNodeType sim_node_for_group= {
+	/* *next,*prev     */	NULL, NULL,
+	/* type code       */	SIM_NODE_FOR_GROUP,
+	/* name            */	"ForGroup",
+	/* width+range     */	140, 100, 320,
+	/* class+opts      */	NODE_CLASS_EXECUTION, 0,
+	/* input sock      */	inputs,
+	/* output sock     */	outputs,
+	/* storage         */	"",
+	/* execfunc        */	NULL,
+	/* butfunc         */	NULL,
+	/* initfunc        */	NULL,
+	/* freestoragefunc */	NULL,
+	/* copysotragefunc */	NULL,
+	/* id              */	NULL,
+	/* pynode, pydict  */	NULL, NULL,
+	/* gpufunc         */	NULL,
+	/* updatefunc      */	NULL,
+	/* socketstoragename */	"",
+	/* initsocketfunc  */	NULL,
+	/* copysocketstoragefunc */	NULL,
+	/* freesocketstoragefunc */	NULL,
+	/* prepare_outputs */	NULL,
+	/* generate_source */	NULL,
+	/* enqueue         */	NULL,
+	/* enqueue         */	enqueue_op
+};





More information about the Bf-blender-cvs mailing list