[Bf-blender-cvs] [9293249] object_nodes: Extension of depsgraph API to handle the relations between node trees.

Lukas Tönne noreply at git.blender.org
Mon Dec 14 13:58:05 CET 2015


Commit: 929324995f841908a59de2d9e276988e64a42117
Author: Lukas Tönne
Date:   Mon Dec 14 12:19:14 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB929324995f841908a59de2d9e276988e64a42117

Extension of depsgraph API to handle the relations between node trees.

This allows node groups and similar nodes with a node tree ID pointer
to register in the depsgraph.

In addition to defining relations, the builder must also make sure
that the node tree depsnodes are created first, because, unlike objects,
node trees depsnodes have no direct scene connection and are not generated
in advance. Since the build process has two distinct steps for creating
nodes and relations, the same API is used for both to simplify the code.

===================================================================

M	release/scripts/nodes/common_nodes.py
M	release/scripts/nodes/group_nodes.py
M	release/scripts/nodes/object_nodes.py
M	source/blender/depsgraph/DEG_depsgraph_build.h
M	source/blender/depsgraph/intern/depsgraph_build.cc
M	source/blender/depsgraph/intern/depsgraph_build.h
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cc
M	source/blender/depsgraph/intern/depsgraph_build_relations.cc
M	source/blender/makesrna/intern/rna_depsgraph.c
M	source/blender/modifiers/intern/MOD_displace.c

===================================================================

diff --git a/release/scripts/nodes/common_nodes.py b/release/scripts/nodes/common_nodes.py
index 71975d0..b0c5b7f 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -62,6 +62,9 @@ class GlobalsBuilder():
     def add_texture_relation(self, tex, component='PARAMETERS', description=""):
         pass
 
+    def add_nodetree_relation(self, ntree, component='PARAMETERS', description=""):
+        pass
+
 
 class NodeTreeBase():
     def depsgraph_update(self, depsnode):
diff --git a/release/scripts/nodes/group_nodes.py b/release/scripts/nodes/group_nodes.py
index 0704053..e2b81eb 100644
--- a/release/scripts/nodes/group_nodes.py
+++ b/release/scripts/nodes/group_nodes.py
@@ -299,9 +299,8 @@ def make_node_group_types(prefix, treetype, node_base):
             layout.template_ID(self, "id", new="object_nodes.geometry_nodes_new")
 
         def relations_update(self, depsnode):
-            if self.id:
-                for node in self.id.nodes:
-                    node.relations_update(depsnode)
+            if self.id is not None:
+                depsnode.add_nodetree_relation(self.id)
 
         def update(self):
             if self.is_updating:
diff --git a/release/scripts/nodes/object_nodes.py b/release/scripts/nodes/object_nodes.py
index fde964f..b0862ad 100644
--- a/release/scripts/nodes/object_nodes.py
+++ b/release/scripts/nodes/object_nodes.py
@@ -69,6 +69,10 @@ class GeometryNode(ObjectNodeBase, ObjectNode):
     def bl_id_property_poll(self, ntree):
         return ntree.bl_idname == 'GeometryNodeTree'
 
+    def relations_update(self, depsnode):
+        if self.id is not None:
+            depsnode.add_nodetree_relation(self.id)
+
     def draw_buttons(self, context, layout):
         layout.template_ID(self, "id", new="object_nodes.geometry_nodes_new")
 
@@ -86,6 +90,10 @@ class ForceFieldNode(ObjectNodeBase, ObjectNode):
     def bl_id_property_poll(self, ntree):
         return ntree.bl_idname == 'ForceFieldNodeTree'
 
+    def relations_update(self, depsnode):
+        if self.id is not None:
+            depsnode.add_nodetree_relation(self.id)
+
     def draw_buttons(self, context, layout):
         layout.template_ID(self, "id", new="object_nodes.force_field_nodes_new")
 
diff --git a/source/blender/depsgraph/DEG_depsgraph_build.h b/source/blender/depsgraph/DEG_depsgraph_build.h
index bcfb035..6e4f430 100644
--- a/source/blender/depsgraph/DEG_depsgraph_build.h
+++ b/source/blender/depsgraph/DEG_depsgraph_build.h
@@ -44,6 +44,7 @@ struct Main;
 struct Object;
 struct Scene;
 struct Tex;
+struct bNodeTree;
 
 struct PointerRNA;
 struct PropertyRNA;
@@ -108,13 +109,18 @@ typedef enum eDepsObjectComponentType {
 } eDepsObjectComponentType;
 
 typedef enum eDepsTextureComponentType {
-	DEG_OB_TEX_PARAMETERS,        /* Parameters Component - Default when nothing else fits (i.e. just SDNA property setting) */
+	DEG_TEX_COMP_PARAMETERS,         /* Parameters Component - Default when nothing else fits (i.e. just SDNA property setting) */
 } eDepsTextureComponentType;
 
+typedef enum eDepsNodeTreeComponentType {
+	DEG_NTREE_COMP_PARAMETERS,    /* Parameters Component - Default when nothing else fits (i.e. just SDNA property setting) */
+} eDepsNodeTreeComponentType;
+
 void DEG_add_scene_relation(struct DepsNodeHandle *node, struct Scene *scene, eDepsSceneComponentType component, const char *description);
 void DEG_add_object_relation(struct DepsNodeHandle *node, struct Object *ob, eDepsObjectComponentType component, const char *description);
 void DEG_add_bone_relation(struct DepsNodeHandle *handle, struct Object *ob, const char *bone_name, eDepsObjectComponentType component, const char *description);
 void DEG_add_texture_relation(struct DepsNodeHandle *handle, struct Tex *tex, eDepsTextureComponentType component, const char *description);
+void DEG_add_nodetree_relation(struct DepsNodeHandle *handle, struct bNodeTree *ntree, eDepsNodeTreeComponentType component, const char *description);
 
 /* TODO(sergey): Remove once all geometry update is granular. */
 void DEG_add_special_eval_flag(struct Depsgraph *graph, struct ID *id, short flag);
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index efbb50c..2a403f1 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -134,41 +134,74 @@ static eDepsNode_Type deg_build_object_component_type(eDepsObjectComponentType c
 static eDepsNode_Type deg_build_texture_component_type(eDepsTextureComponentType component)
 {
 	switch (component) {
-		case DEG_OB_TEX_PARAMETERS:         return DEPSNODE_TYPE_PARAMETERS;
+		case DEG_TEX_COMP_PARAMETERS:          return DEPSNODE_TYPE_PARAMETERS;
+	}
+	return DEPSNODE_TYPE_UNDEFINED;
+}
+
+static eDepsNode_Type deg_build_nodetree_component_type(eDepsNodeTreeComponentType component)
+{
+	switch (component) {
+		case DEG_NTREE_COMP_PARAMETERS:     return DEPSNODE_TYPE_PARAMETERS;
 	}
 	return DEPSNODE_TYPE_UNDEFINED;
 }
 
 void DEG_add_scene_relation(DepsNodeHandle *handle, struct Scene *scene, eDepsSceneComponentType component, const char *description)
 {
-	eDepsNode_Type type = deg_build_scene_component_type(component);
-	ComponentKey comp_key(&scene->id, type);
-	handle->builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
+	if (handle->relation_builder) {
+		eDepsNode_Type type = deg_build_scene_component_type(component);
+		ComponentKey comp_key(&scene->id, type);
+		handle->relation_builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
+	}
 }
 
 void DEG_add_object_relation(DepsNodeHandle *handle, struct Object *ob, eDepsObjectComponentType component, const char *description)
 {
-	eDepsNode_Type type = deg_build_object_component_type(component);
-	ComponentKey comp_key(&ob->id, type);
-	handle->builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
+	if (handle->relation_builder) {
+		eDepsNode_Type type = deg_build_object_component_type(component);
+		ComponentKey comp_key(&ob->id, type);
+		handle->relation_builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
+	}
 }
 
 void DEG_add_bone_relation(DepsNodeHandle *handle, struct Object *ob, const char *bone_name, eDepsObjectComponentType component, const char *description)
 {
-	eDepsNode_Type type = deg_build_object_component_type(component);
-	ComponentKey comp_key(&ob->id, type, bone_name);
-
-	// XXX: "Geometry Eval" might not always be true, but this only gets called from modifier building now
-	handle->builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
+	if (handle->relation_builder) {
+		eDepsNode_Type type = deg_build_object_component_type(component);
+		ComponentKey comp_key(&ob->id, type, bone_name);
+		
+		// XXX: "Geometry Eval" might not always be true, but this only gets called from modifier building now
+		handle->relation_builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
+	}
 }
 
 void DEG_add_texture_relation(DepsNodeHandle *handle, struct Tex *tex, eDepsTextureComponentType component, const char *description)
 {
-	eDepsNode_Type type = deg_build_texture_component_type(component);
-	ComponentKey comp_key(&tex->id, type);
-	handle->builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_STANDARD, description);
+	if (handle->node_builder) {
+		handle->node_builder->build_texture(NULL, tex);
+	}
+	if (handle->relation_builder) {
+		eDepsNode_Type type = deg_build_texture_component_type(component);
+		ComponentKey comp_key(&tex->id, type);
+		handle->relation_builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_STANDARD, description);
+	}
 }
 
+void DEG_add_nodetree_relation(DepsNodeHandle *handle, struct bNodeTree *ntree, eDepsNodeTreeComponentType component, const char *description)
+{
+	if (handle->node_builder) {
+		handle->node_builder->build_nodetree(NULL, ntree);
+	}
+	if (handle->relation_builder) {
+		eDepsNode_Type type = deg_build_nodetree_component_type(component);
+		ComponentKey comp_key(&ntree->id, type);
+		
+		handle->relation_builder->build_nodetree(NULL, ntree);
+		
+		handle->relation_builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_STANDARD, description);
+	}
+}
 void DEG_add_special_eval_flag(Depsgraph *graph, ID *id, short flag)
 {
 	if (graph == NULL) {
@@ -383,3 +416,25 @@ void DEG_scene_graph_free(Scene *scene)
 		scene->depsgraph = NULL;
 	}
 }
+
+void deg_build_nodetree_rna(bNodeTree *ntree, DepsNodeHandle *handle)
+{
+	PointerRNA ptr;
+	ParameterList list;
+	FunctionRNA *func;
+	
+	if (!ntree->typeinfo->ext.call)
+		return;
+	
+	RNA_id_pointer_create((ID *)ntree, &ptr);
+	
+	func = RNA_struct_find_function(ptr.type, "depsgraph_update");
+	if (!func)
+		return;
+	
+	RNA_parameter_list_create(&list, &ptr, func);
+	RNA_parameter_set_lookup(&list, "depsnode", &handle);
+	ntree->typeinfo->ext.call(NULL, &ptr, func, &list);
+	
+	RNA_parameter_list_free(&list);
+}
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index c5b04ec..aac99ef 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -127,6 +127,9 @@ struct DepsgraphNodeBuilder {
 	void build_compositor(Scene *scene);
 	void build_gpencil(bGPdata *gpd);
 
+protected:
+	DepsNodeHandle create_node_handle();
+
 private:
 	Main *m_bmain;
 	Depsgraph *m_graph;
@@ -305,15 +308,25 @@ private:
 
 struct DepsNodeHandle
 {
+	DepsNodeHandle(DepsgraphNodeBuilder *builder) :
+	    node_builder(builder),
+	    relation_builder(NULL),
+	    node(NULL),
+	    default_name("")
+	{
+	}
+	
 	DepsNodeHandle(DepsgraphRelationBuilder *builder, OperationDepsNode *node, const string &default_name = "") :
-	    builder(builder),
+	    node_builder(NULL),
+	    relation_builder(builder),
 	    node(node),
 	    default_name(default_name)
 	{
 		BLI_assert(node != NULL);
 	}
 
-	DepsgraphRelationBuilder *builder;
+	DepsgraphNodeBuilder *node_builder;
+	Dep

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list