[Bf-blender-cvs] [aba7952] depsgraph_refactor: Added "ID Users" depsgraph builder, for setting up links between ID datablocks

Joshua Leung noreply at git.blender.org
Fri Jan 2 05:15:21 CET 2015


Commit: aba7952caf812887e86f5bd1a472b63022f4b86c
Author: Joshua Leung
Date:   Fri Jan 2 16:38:24 2015 +1300
Branches: depsgraph_refactor
https://developer.blender.org/rBaba7952caf812887e86f5bd1a472b63022f4b86c

Added "ID Users" depsgraph builder, for setting up links between ID datablocks

This is useful for one-to-many situations when building relationships between
operations, but is likely to come in handy for other parts of Blender later
on.

For example, when constructing drivers on armature bones, we don't have any easy
way of referring back to the object (and thus the pose bones) to make those
depend on these as well.

Just a few skeleton types have been implemented now.

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

M	source/blender/depsgraph/CMakeLists.txt
M	source/blender/depsgraph/intern/depsgraph_build.cpp
M	source/blender/depsgraph/intern/depsgraph_build.h
A	source/blender/depsgraph/intern/depsgraph_build_idusers.cpp

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

diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index 0c4164b7..fee966d 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -50,6 +50,7 @@ set(SRC
 	intern/depsgraph_build.cpp
 	intern/depsgraph_build_nodes.cpp
 	intern/depsgraph_build_relations.cpp
+	intern/depsgraph_build_idusers.cpp
 	intern/depsgraph_debug.cpp
 	intern/depsgraph_eval.cpp
 	intern/depsgraph_query.cpp
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cpp b/source/blender/depsgraph/intern/depsgraph_build.cpp
index 6202617..338bb58 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build.cpp
@@ -483,7 +483,36 @@ static void deg_graph_flush_node_layers(Depsgraph *graph)
 	}
 }
 
-/* -------------------------------------------------- */
+/* ************************************************* */
+/* Datablock User Relationships Builder */
+
+DepsgraphIDUsersBuilder::DepsgraphIDUsersBuilder(Depsgraph *graph) :
+    m_graph(graph)
+{
+}
+
+
+void DepsgraphIDUsersBuilder::add_relation(const ID *from_id, const ID *to_id,
+	                                       eDepsRelation_Type type, const string &description)
+{
+	IDDepsNode *node_from = m_graph->find_id_node(from_id);
+	IDDepsNode *node_to = m_graph->find_id_node(to_id);
+	
+	if (node_from && node_to) {
+		m_graph->add_new_relation(node_from, node_to, type, description);
+	}
+	else {
+		fprintf(stderr, "ID Builder add_relation(%s => %s, %s => %s, %d, %s) Failed\n",
+		        (from_id) ? from_id->name : "<No ID>",
+		        (node_from) ? node_from->identifier().c_str() : "<None>",
+		        (to_id) ? to_id->name : "<No ID>",
+		        (node_to)   ? node_to->identifier().c_str() : "<None>",
+		        type, description.c_str());
+	}
+}
+
+/* ************************************************* */
+/* Graph Building API's */
 
 /* Build depsgraph for the given scene, and dump results in given graph container */
 // XXX: assume that this is called from outside, given the current scene as the "main" scene 
@@ -497,6 +526,7 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
 	BKE_main_id_tag_idcode(bmain, ID_WO, false);
 	BKE_main_id_tag_idcode(bmain, ID_TE, false);
 	
+	/* 1) Generate all the nodes in the graph first */
 	DepsgraphNodeBuilder node_builder(bmain, graph);
 	/* create root node for scene first
 	 * - this way it should be the first in the graph,
@@ -505,6 +535,14 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
 	node_builder.add_root_node();
 	node_builder.build_scene(scene);
 	
+	/* 2) Generate relationships between ID nodes and/or components, to make it easier to keep track
+	 *    of which datablocks use which ones (e.g. for checking which objects share the same geometry
+	 *    when we only know the shared datablock)
+	 */
+	DepsgraphIDUsersBuilder users_builder(graph);
+	users_builder.build_scene(scene);
+	
+	/* 3) Hook up relationships between operations - to determine evaluation order */
 	DepsgraphRelationBuilder relation_builder(graph);
 	/* hook scene up to the root node as entrypoint to graph */
 	/* XXX what does this relation actually mean?
@@ -514,7 +552,10 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
 	relation_builder.build_scene(scene);
 	
 	
+	/* 4) Simplify the graph by removing redundant relations (to optimise traversal later) */
+	// TODO: it would be useful to have an option to disable this in cases where it is causing trouble
 	deg_graph_transitive_reduction(graph);
+	
 	deg_graph_flush_node_layers(graph);
 }
 
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index 16b7ff0..6217095 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -276,6 +276,20 @@ private:
 	Depsgraph *m_graph;
 };
 
+struct DepsgraphIDUsersBuilder {
+	DepsgraphIDUsersBuilder(Depsgraph *graph);
+	
+	void add_relation(const ID *from_id, const ID *to_id,
+	                  eDepsRelation_Type type, const string &description);
+	
+	void build_scene(Scene *scene);
+	void build_object(Scene *scene, Object *ob);
+	
+private:
+	Depsgraph *m_graph;
+};
+
+
 struct DepsNodeHandle 
 {
 	DepsNodeHandle(DepsgraphRelationBuilder *builder, OperationDepsNode *node, const string &default_name = "") :
diff --git a/source/blender/depsgraph/intern/depsgraph_build_idusers.cpp b/source/blender/depsgraph/intern/depsgraph_build_idusers.cpp
new file mode 100644
index 0000000..6f93979
--- /dev/null
+++ b/source/blender/depsgraph/intern/depsgraph_build_idusers.cpp
@@ -0,0 +1,187 @@
+/*
+ * ***** 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) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Joshua Leung
+ * Contributor(s): None Yet
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * Methods for adding the links between datablocks to the depsgraph
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+extern "C" {
+#include "BLI_blenlib.h"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_action_types.h"
+#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_effect_types.h"
+#include "DNA_group_types.h"
+#include "DNA_key_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meta_types.h"
+#include "DNA_node_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_object_types.h"
+#include "DNA_rigidbody_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_world_types.h"
+
+#include "BKE_action.h"
+#include "BKE_armature.h"
+#include "BKE_animsys.h"
+#include "BKE_constraint.h"
+#include "BKE_curve.h"
+#include "BKE_effect.h"
+#include "BKE_fcurve.h"
+#include "BKE_group.h"
+#include "BKE_key.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
+#include "BKE_mball.h"
+#include "BKE_modifier.h"
+#include "BKE_node.h"
+#include "BKE_object.h"
+#include "BKE_particle.h"
+#include "BKE_rigidbody.h"
+#include "BKE_sound.h"
+#include "BKE_texture.h"
+#include "BKE_tracking.h"
+#include "BKE_world.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
+#include "RNA_access.h"
+#include "RNA_types.h"
+} /* extern "C" */
+
+#include "depsnode.h"
+#include "depsnode_component.h"
+#include "depsnode_operation.h"
+#include "depsgraph_types.h"
+#include "depsgraph_build.h"
+#include "depsgraph_eval.h"
+#include "depsgraph_intern.h"
+
+/* ******************************************** */
+/* ID User Builder */
+
+void DepsgraphIDUsersBuilder::build_scene(Scene *scene)
+{
+	/* scene set - do links to other scenes */
+	if (scene->set) {
+		// XXX: how?
+	}
+	
+	/* scene objects */
+	for (Base *base = (Base *)scene->base.first; base; base = base->next) {
+		Object *ob = base->object;
+		build_object(scene, ob);
+	}
+	
+	/* world */
+	if (scene->world) {
+		//build_world(scene->world);
+	}
+	
+	/* compo nodes */
+	if (scene->nodetree) {
+		//build_compositor(scene);
+	}
+	
+	// XXX: scene's other data
+}
+
+void DepsgraphIDUsersBuilder::build_object(Scene *scene, Object *ob)
+{
+	ID *ob_id = &ob->id;
+	
+	/* scene -> object */
+	add_relation(&scene->id, ob_id, DEPSREL_TYPE_DATABLOCK, "Scene Object"); 
+	
+	/* object animation */
+	//build_animdata(&ob->id);
+	
+	/* object datablock */
+	if (ob->data) {
+		ID *obdata_id = (ID *)ob->data;
+		
+		/* object -> obdata */
+		add_relation(ob_id, obdata_id, DEPSREL_TYPE_DATABLOCK, "Object Data");
+		
+		/* ob data animation */
+		//build_animdata(obdata_id);
+		
+		/* type-specific data... */
+		switch (ob->type) {
+			case OB_MESH:     /* Geometry */
+			case OB_CURVE:
+			case OB_FONT:
+			case OB_SURF:
+			case OB_MBALL:
+			case OB_LATTICE:
+			{
+				/* obdata -> geometry (i.e. shapekeys) */
+				//build_obdata_geom(scene, ob);
+				
+				/* materials */
+				
+				/* modifiers */
+			}
+			break;
+			
+			
+			case OB_ARMATURE: /* Pose */
+				/* rig -> custom shapes? */
+				//build_rig(scene, ob);
+				break;
+			
+			case OB_LAMP:   /* Lamp */
+				//build_lamp(ob);
+				break;
+				
+			case OB_CAMERA: /* Camera */
+				//build_camera(ob);
+				break;
+		}
+	}
+	
+	/* proxy */
+	
+	/* dupligroups? */
+}
+
+/* ******************************************** */




More information about the Bf-blender-cvs mailing list