[Bf-blender-cvs] [04e6af8] depsgraph_refactor: Depsgraph: Move pose evaluation callbacks from temporary stub to blenkernel

Sergey Sharybin noreply at git.blender.org
Wed Jan 14 14:48:27 CET 2015


Commit: 04e6af8189de6e17b103abe3b63f5cadfd2a7c36
Author: Sergey Sharybin
Date:   Wed Jan 14 18:43:22 2015 +0500
Branches: depsgraph_refactor
https://developer.blender.org/rB04e6af8189de6e17b103abe3b63f5cadfd2a7c36

Depsgraph: Move pose evaluation callbacks from temporary stub to blenkernel

Now all the callback functions used by dependency graph are moved to dedicated
armature_update.c file in blenkernel.

There are also some spline IK functions moved from armature.c to the new file
which isn't strictly related on the original change but without any file in
blenkernel using functions from the new armature_update there'll be a linking
error. It also seems not so crazy idea to concentrate all the pose evaluation
in a single file, so overall it's not so much bad. Just annoying stupidnes
of compiler forced to do such a move now.

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

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/armature.c
A	source/blender/blenkernel/intern/armature_update.c
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 0bc2126..ce7b95e 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -146,6 +146,7 @@ void b_bone_spline_setup(struct bPoseChannel *pchan, int rest, Mat4 result_array
 /* Evaluation helpers */
 struct bKinematicConstraint;
 struct bSplineIKConstraint;
+struct EvaluationContext;
 
 struct bPoseChannel *BKE_armature_ik_solver_find_root(struct bPoseChannel *pchan,
                                                       struct bKinematicConstraint *data);
@@ -155,6 +156,35 @@ struct bPoseChannel* BKE_armature_splineik_solver_find_root(struct bPoseChannel
 void BKE_pose_splineik_init_tree(struct Scene *scene, struct Object *ob, float ctime);
 void BKE_splineik_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime);
 
+void BKE_pose_eval_init(struct EvaluationContext *eval_ctx,
+                        struct Scene *scene,
+                        struct Object *ob,
+                        struct bPose *pose);
+
+void BKE_pose_eval_bone(struct EvaluationContext *eval_ctx,
+                        struct Scene *scene,
+                        struct Object *ob,
+                        struct bPoseChannel *pchan);
+
+void BKE_pose_constraints_evaluate(struct EvaluationContext *eval_ctx,
+                                   struct Object *ob,
+                                   struct bPoseChannel *pchan);
+
+void BKE_pose_iktree_evaluate(struct EvaluationContext *eval_ctx,
+                              struct Scene *scene,
+                              struct Object *ob,
+                              struct bPoseChannel *rootchan);
+
+void BKE_pose_splineik_evaluate(struct EvaluationContext *eval_ctx,
+                                struct Scene *scene,
+                                struct Object *ob,
+                                struct bPoseChannel *rootchan);
+
+void BKE_pose_eval_flush(struct EvaluationContext *eval_ctx,
+                         struct Scene *scene,
+                         struct Object *ob,
+                         struct bPose *pose);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 55df1f8..bfd6a02 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -67,6 +67,7 @@ set(SRC
 	intern/anim_sys.c
 	intern/appdir.c
 	intern/armature.c
+	intern/armature_update.c
 	intern/autoexec.c
 	intern/blender.c
 	intern/bmfont.c
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 2eb8156..d7187a4 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -1826,498 +1826,6 @@ void BKE_pose_rebuild(Object *ob, bArmature *arm)
 }
 
 
-/* ********************** SPLINE IK SOLVER ******************* */
-
-/* Temporary evaluation tree data used for Spline IK */
-typedef struct tSplineIK_Tree {
-	struct tSplineIK_Tree *next, *prev;
-
-	int type;                    /* type of IK that this serves (CONSTRAINT_TYPE_KINEMATIC or ..._SPLINEIK) */
-
-	bool free_points;            /* free the point positions array */
-	short chainlen;              /* number of bones in the chain */
-
-	float *points;               /* parametric positions for the joints along the curve */
-	bPoseChannel **chain;        /* chain of bones to affect using Spline IK (ordered from the tip) */
-
-	bPoseChannel *root;          /* bone that is the root node of the chain */
-
-	bConstraint *con;            /* constraint for this chain */
-	bSplineIKConstraint *ikData; /* constraint settings for this chain */
-} tSplineIK_Tree;
-
-/* ----------- */
-
-/* Tag the bones in the chain formed by the given bone for IK */
-static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPoseChannel *pchan_tip)
-{
-	bPoseChannel *pchan, *pchanRoot = NULL;
-	bPoseChannel *pchanChain[255];
-	bConstraint *con = NULL;
-	bSplineIKConstraint *ikData = NULL;
-	float boneLengths[255], *jointPoints;
-	float totLength = 0.0f;
-	bool free_joints = 0;
-	int segcount = 0;
-
-	/* find the SplineIK constraint */
-	for (con = pchan_tip->constraints.first; con; con = con->next) {
-		if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
-			ikData = con->data;
-
-			/* target can only be curve */
-			if ((ikData->tar == NULL) || (ikData->tar->type != OB_CURVE))
-				continue;
-			/* skip if disabled */
-			if ((con->enforce == 0.0f) || (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)))
-				continue;
-
-			/* otherwise, constraint is ok... */
-			break;
-		}
-	}
-	if (con == NULL)
-		return;
-
-	/* make sure that the constraint targets are ok
-	 *     - this is a workaround for a depsgraph bug...
-	 */
-	if (ikData->tar) {
-		/* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
-		 *       currently for paths to work it needs to go through the bevlist/displist system (ton)
-		 */
-
-		/* only happens on reload file, but violates depsgraph still... fix! */
-		if (ELEM(NULL,  ikData->tar->curve_cache, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) {
-			BKE_displist_make_curveTypes(scene, ikData->tar, 0);
-			
-			/* path building may fail in EditMode after removing verts [#33268]*/
-			if (ELEM(NULL, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) {
-				/* BLI_assert(cu->path != NULL); */
-				return;
-			}
-		}
-	}
-
-	/* find the root bone and the chain of bones from the root to the tip
-	 * NOTE: this assumes that the bones are connected, but that may not be true... */
-	for (pchan = pchan_tip; pchan && (segcount < ikData->chainlen); pchan = pchan->parent, segcount++) {
-		/* store this segment in the chain */
-		pchanChain[segcount] = pchan;
-
-		/* if performing rebinding, calculate the length of the bone */
-		boneLengths[segcount] = pchan->bone->length;
-		totLength += boneLengths[segcount];
-	}
-
-	if (segcount == 0)
-		return;
-	else
-		pchanRoot = pchanChain[segcount - 1];
-
-	/* perform binding step if required */
-	if ((ikData->flag & CONSTRAINT_SPLINEIK_BOUND) == 0) {
-		float segmentLen = (1.0f / (float)segcount);
-		int i;
-
-		/* setup new empty array for the points list */
-		if (ikData->points)
-			MEM_freeN(ikData->points);
-		ikData->numpoints = ikData->chainlen + 1;
-		ikData->points = MEM_mallocN(sizeof(float) * ikData->numpoints, "Spline IK Binding");
-
-		/* bind 'tip' of chain (i.e. first joint = tip of bone with the Spline IK Constraint) */
-		ikData->points[0] = 1.0f;
-
-		/* perform binding of the joints to parametric positions along the curve based
-		 * proportion of the total length that each bone occupies
-		 */
-		for (i = 0; i < segcount; i++) {
-			/* 'head' joints, traveling towards the root of the chain
-			 *  - 2 methods; the one chosen depends on whether we've got usable lengths
-			 */
-			if ((ikData->flag & CONSTRAINT_SPLINEIK_EVENSPLITS) || (totLength == 0.0f)) {
-				/* 1) equi-spaced joints */
-				ikData->points[i + 1] = ikData->points[i] - segmentLen;
-			}
-			else {
-				/* 2) to find this point on the curve, we take a step from the previous joint
-				 *    a distance given by the proportion that this bone takes
-				 */
-				ikData->points[i + 1] = ikData->points[i] - (boneLengths[i] / totLength);
-			}
-		}
-
-		/* spline has now been bound */
-		ikData->flag |= CONSTRAINT_SPLINEIK_BOUND;
-	}
-
-	/* disallow negative values (happens with float precision) */
-	CLAMP_MIN(ikData->points[segcount], 0.0f);
-
-	/* apply corrections for sensitivity to scaling on a copy of the bind points,
-	 * since it's easier to determine the positions of all the joints beforehand this way
-	 */
-	if ((ikData->flag & CONSTRAINT_SPLINEIK_SCALE_LIMITED) && (totLength != 0.0f)) {
-		float splineLen, maxScale;
-		int i;
-
-		/* make a copy of the points array, that we'll store in the tree
-		 *     - although we could just multiply the points on the fly, this approach means that
-		 *       we can introduce per-segment stretchiness later if it is necessary
-		 */
-		jointPoints = MEM_dupallocN(ikData->points);
-		free_joints = 1;
-
-		/* get the current length of the curve */
-		/* NOTE: this is assumed to be correct even after the curve was resized */
-		splineLen = ikData->tar->curve_cache->path->totdist;
-
-		/* calculate the scale factor to multiply all the path values by so that the
-		 * bone chain retains its current length, such that
-		 *     maxScale * splineLen = totLength
-		 */
-		maxScale = totLength / splineLen;
-
-		/* apply scaling correction to all of the temporary points */
-		/* TODO: this is really not adequate enough on really short chains */
-		for (i = 0; i < segcount; i++)
-			jointPoints[i] *= maxScale;
-	}
-	else {
-		/* just use the existing points array */
-		jointPoints = ikData->points;
-		free_joints = 0;
-	}
-
-	/* make a new Spline-IK chain, and store it in the IK chains */
-	/* TODO: we should check if there is already an IK chain on this, since that would take presidence... */
-	{
-		/* make new tree */
-		tSplineIK_Tree *tree = MEM_callocN(sizeof(tSplineIK_Tree), "SplineIK Tree");
-		tree->type = CONSTRAINT_TYPE_SPLINEIK;
-
-		tree->chainlen = segcount;
-
-		/* copy over the array of links to bones in the chain (from tip to root) */
-		tree->chain = MEM_mallocN(sizeof(bPoseChannel *) * segcount, "SplineIK Chain");
-		memcpy(tree->chain, pchanChain, sizeof(bPoseChannel *) * segcount);
-
-		/* store reference to joint position array */
-		tree->points = jointPoints;
-		tree->free_points = free_joints;
-
-		/* store references to different parts of the chain */
-		tree->root = pchanRoot;
-		tree->con = con;
-		tree->ikData = ikData;
-
-		/* AND! link the tree to the root */
-		BLI_addtail(&pchanRoot->siktree, tree);
-	}
-
-	/* mark root channel having an IK tree */
-	pchanRoot->flag |= POSE_IKSPLINE;
-}
-
-/* Tag which bones are members of Spline IK chains */
-static void splineik_init_tree(Scene *scene, Object *ob, float UNUSED(ctime))
-{
-	bPoseChannel *pchan;
-
-	/* find the tips of Spline IK chains, which are simp

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list