[Bf-blender-cvs] [2cff1de] depsgraph_refactor: Depsgraph: Initial move towards more granular armatures update

Sergey Sharybin noreply at git.blender.org
Thu Nov 20 14:57:00 CET 2014


Commit: 2cff1dece0ffa4cfa69cf1e239c89eef14b5133d
Author: Sergey Sharybin
Date:   Tue Nov 18 10:17:13 2014 +0100
Branches: depsgraph_refactor
https://developer.blender.org/rB2cff1dece0ffa4cfa69cf1e239c89eef14b5133d

Depsgraph: Initial move towards more granular armatures update

Main goal is to be able to do interleaved updates of bones from different armatures,
so it'll be possible to drive some bones of armature B with bones of armature B and
drive other bones in an opposite direction. This also beans interleaved update of
bones from the same armature should be possible.

This commit adds an initial support of this but have some limitation still, for
example drivers are not supported yet at all. Spline IK is also not supported in the
granular update. IK solver is so called "seems to work" state, but might need some
extra work.

Some technical details of the changes:

- Basically just filled in existing callbacks which so far were doing nothing,
  also needed to fix some typos in the code.

- Changed the Bone component a bit, so now it does have "Final Transform" NOOP
  node which would guarantee Bone component depends on the IK solver if it exists.

  So now all the external dependencies would use bone transform after the solver,
  plus bones child which are not in the solver would use solved transform of the
  bone.

  This required changes in the relations of the IK solver as well, so now it
  depends on the bone local transform and optionally on the bone constraint stack.

- Currently scene is being passed for the current time, in the future we need to
  pass time source node instead.

This would likely break some setups which used to work before going granular, but
even at that time update wasn't finished at all.

There are some known TODOs about making code more clean in the change, will be
solved later.

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

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/object_update.c
M	source/blender/depsgraph/intern/depsgraph_build.h
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
M	source/blender/depsgraph/intern/depsgraph_build_relations.cpp
M	source/blender/depsgraph/intern/depsgraph_type_defines.cpp
M	source/blender/depsgraph/intern/stubs.h

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

diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index fdf0795..ba0db26 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -143,6 +143,9 @@ void b_bone_spline_setup(struct bPoseChannel *pchan, int rest, Mat4 result_array
 #define PBONE_SELECTABLE(arm, bone) \
 	(PBONE_VISIBLE(arm, bone) && !((bone)->flag & BONE_UNSELECTABLE))
 
+/* Evaluation helpers */
+void BKE_pose_splineik_init_tree(struct Scene *scene, struct Object *ob, float ctime);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index d3dcb2b..7e0898c 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -2024,6 +2024,11 @@ static void splineik_init_tree(Scene *scene, Object *ob, float UNUSED(ctime))
 	}
 }
 
+void BKE_pose_splineik_init_tree(Scene *scene, Object *ob, float ctime)
+{
+	splineik_init_tree(scene, ob, ctime);
+}
+
 /* ----------- */
 
 /* Evaluate spline IK for a given bone */
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 708a901..64a8d28 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -268,5 +268,6 @@ void BKE_object_eval_uber_data(EvaluationContext *eval_ctx,
                                Object *ob)
 {
 	PRINT("%s on %s\n", __func__, ob->id.name);
+	BLI_assert(ob->type != OB_ARMATURE);
 	BKE_object_handle_data_update(eval_ctx, scene, ob);
 }
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h b/source/blender/depsgraph/intern/depsgraph_build.h
index 19843f4..c2fb730 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -135,9 +135,9 @@ struct DepsgraphNodeBuilder {
 	void build_particles(Object *ob);
 	void build_animdata(ID *id);
 	OperationDepsNode *build_driver(ID *id, FCurve *fcurve);
-	void build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con);
+	void build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con);
 	void build_splineik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con);
-	void build_rig(Object *ob);
+	void build_rig(Scene *scene, Object *ob);
 	void build_shapekeys(Key *key);
 	void build_obdata_geom(Scene *scene, Object *ob);
 	void build_camera(Object *ob);
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index 85bf12f..8835d47 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -263,7 +263,7 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Object *ob)
 			break;
 			
 			case OB_ARMATURE: /* Pose */
-				build_rig(ob);
+				build_rig(scene, ob);
 				break;
 			
 			case OB_LAMP:   /* Lamp */
@@ -288,9 +288,12 @@ void DepsgraphNodeBuilder::build_object(Scene *scene, Object *ob)
 	 *
 	 * TODO(sergey): Get rid of this node.
 	 */
-	add_operation_node(&ob->id, DEPSNODE_TYPE_GEOMETRY,
-	                   DEPSOP_TYPE_EXEC, bind(BKE_object_eval_uber_data, _1, scene, ob),
-	                   "Object Data UberEval");
+	if (ob->type != OB_ARMATURE) {
+		/* Armatures does no longer require uber node. */
+		add_operation_node(&ob->id, DEPSNODE_TYPE_GEOMETRY,
+		                   DEPSOP_TYPE_EXEC, bind(BKE_object_eval_uber_data, _1, scene, ob),
+		                   "Object Data UberEval");
+	}
 
 }
 
@@ -504,7 +507,7 @@ void DepsgraphNodeBuilder::build_particles(Object *ob)
 }
 
 /* IK Solver Eval Steps */
-void DepsgraphNodeBuilder::build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con)
+void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con)
 {
 	bKinematicConstraint *data = (bKinematicConstraint *)con->data;
 	
@@ -527,8 +530,8 @@ void DepsgraphNodeBuilder::build_ik_pose(Object *ob, bPoseChannel *pchan, bConst
 	}
 	
 	/* operation node for evaluating/running IK Solver */
-	add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, pchan->name,
-	                   DEPSOP_TYPE_SIM, bind(BKE_pose_iktree_evaluate, _1, ob, rootchan),
+	add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
+	                   DEPSOP_TYPE_SIM, bind(BKE_pose_iktree_evaluate, _1, scene, ob, rootchan),
 	                   deg_op_name_ik_solver);
 }
 
@@ -558,7 +561,7 @@ void DepsgraphNodeBuilder::build_splineik_pose(Object *ob, bPoseChannel *pchan,
 }
 
 /* Pose/Armature Bones Graph */
-void DepsgraphNodeBuilder::build_rig(Object *ob)
+void DepsgraphNodeBuilder::build_rig(Scene *scene, Object *ob)
 {
 	bArmature *arm = (bArmature *)ob->data;
 	
@@ -596,18 +599,21 @@ void DepsgraphNodeBuilder::build_rig(Object *ob)
 	                   DEPSOP_TYPE_REBUILD, bind(BKE_pose_rebuild_op, _1, ob, ob->pose), deg_op_name_pose_rebuild);
 	
 	add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE,
-	                   DEPSOP_TYPE_INIT, bind(BKE_pose_eval_init, _1, ob, ob->pose), deg_op_name_pose_eval_init);
+	                   DEPSOP_TYPE_INIT, bind(BKE_pose_eval_init, _1, scene, ob, ob->pose), deg_op_name_pose_eval_init);
 	
 	add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE,
-	                   DEPSOP_TYPE_POST, bind(BKE_pose_eval_flush, _1, ob, ob->pose), deg_op_name_pose_eval_flush);
+	                   DEPSOP_TYPE_POST, bind(BKE_pose_eval_flush, _1, scene, ob, ob->pose), deg_op_name_pose_eval_flush);
 	
 	/* bones */
 	for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) {
 		/* node for bone eval */
 		add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
-		                   DEPSOP_TYPE_EXEC, bind(BKE_pose_eval_bone, _1, ob, pchan),
+		                   DEPSOP_TYPE_EXEC, bind(BKE_pose_eval_bone, _1, scene, ob, pchan),
 		                   "Bone Transforms");
-		
+
+		add_operation_node(&ob->id, DEPSNODE_TYPE_BONE, pchan->name,
+		                   DEPSOP_TYPE_EXEC, NULL, "Bone Final Transforms");
+
 		/* constraints */
 		if (pchan->constraints.first != NULL) {
 			build_pose_constraints(ob, pchan);
@@ -625,7 +631,7 @@ void DepsgraphNodeBuilder::build_rig(Object *ob)
 		for (bConstraint *con = (bConstraint *)pchan->constraints.first; con; con = con->next) {
 			switch (con->type) {
 				case CONSTRAINT_TYPE_KINEMATIC:
-					build_ik_pose(ob, pchan, con);
+					build_ik_pose(scene, ob, pchan, con);
 					break;
 					
 				case CONSTRAINT_TYPE_SPLINEIK:
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index 4a7743e..d00a48a 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -265,7 +265,7 @@ void DepsgraphRelationBuilder::build_object(Scene *scene, Object *ob)
 		add_relation(adt_key, local_transform_key, DEPSREL_TYPE_OPERATION, "Object Animation");
 	}
 
-	/* TODO(sergey): This is a temp solution for now only/ */
+	/* TODO(sergey): This is a temp solution for now only. */
 	ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM);
 	ComponentKey geometry_key(&ob->id, DEPSNODE_TYPE_GEOMETRY);
 	add_relation(transform_key, geometry_key, DEPSREL_TYPE_COMPONENT_ORDER, "Object Transform");
@@ -407,17 +407,8 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode
 				}
 				else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
 					/* bone */
-#if 0
 					ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget);
 					add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
-#else
-					/* TODO(sergey): Bones evaluation currently happens in the uber data update node.. */
-					/* TODO(sergey): Once granularity is reached it sohuld be possible to get rid of this check. */
-					if (&ct->tar->id != id) {
-						ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM);
-						add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
-					}
-#endif
 				}
 				else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
 					/* vertex group */
@@ -715,6 +706,36 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
 	// TODO...
 }
 
+BLI_INLINE OperationKey bone_transforms_key(Object *ob,
+                                            bPoseChannel *pchan)
+{
+	if (pchan->constraints.first != NULL) {
+		return OperationKey(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, deg_op_name_constraint_stack);
+	}
+	return OperationKey(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, "Bone Transforms");
+}
+
+/* TODO(sergey): Deduplicate with the node builder.  */
+static bPoseChannel* ik_solver_rootchan_find(bPoseChannel *pchan,
+                                             bKinematicConstraint *data)
+{
+	bPoseChannel *rootchan = pchan;
+	/* exclude tip from chain? */
+	if (!(data->flag & CONSTRAINT_IK_TIP)) {
+		rootchan = rootchan->parent;
+	}
+	if (rootchan) {
+		size_t segcount = 0;
+		while (rootchan->parent) {
+			/* continue up chain, until we reach target number of items... */
+			segcount++;
+			if ((segcount == data->rootbone) || (segcount > 255)) break;  /* XXX 255 is weak */
+			rootchan = rootchan->parent;
+		}
+	}
+	return rootchan;
+}
+
 /* IK Solver Eval Steps */
 void DepsgraphRelationBuilder::build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con)
 {
@@ -724,10 +745,24 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, bPoseChannel *pchan, bC
 	 * - assume that owner is always part of chain 
 	 * - see notes on direction of rel below...
 	 */
-	ComponentKey bone_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name);
-	OperationKey solver_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, pchan->name, deg_op_name_spline_ik_solver);
-	add_relation(bone_key, solver_key, DEPSREL_TYPE_TRANSFORM, "IK Solver Owner");
-	
+	bPoseChannel *rootchan = ik_solver_rootchan_find(pchan, data);
+	OperationKey transforms_key = bone_transforms_key(ob, pchan);
+	OperationKey solver_key(&ob->id, DEPS

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list