Commit: 2d58cb899805389bb7e6a6e431de0636f2ca546f
Author: Sergey Sharybin
Date:   Thu Nov 20 16:11:28 2014 +0100
Branches: depsgraph_refactor
https://developer.blender.org/rB2d58cb899805389bb7e6a6e431de0636f2ca546f

Depsgraph: Hook up spline IK solver to the granular update

A bit of test of prove-of-concept of the design made in the previous commit.
still needs a bit of cleanup (de-duplicate some logic, move functions to their
final location etc).

But currently it's good enough for testing i guess.

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

M       source/blender/blenkernel/BKE_armature.h
M       source/blender/blenkernel/intern/armature.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 ba0db26..4c78648 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -145,6 +145,7 @@ void b_bone_spline_setup(struct bPoseChannel *pchan, int 
rest, Mat4 result_array
 
 /* Evaluation helpers */
 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);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/armature.c 
b/source/blender/blenkernel/intern/armature.c
index 7e0898c..e7e0aff 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -2642,3 +2642,8 @@ BoundBox *BKE_armature_boundbox_get(Object *ob)
 
        return ob->bb;
 }
+
+void BKE_splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel 
*pchan_root, float ctime)
+{
+       splineik_execute_tree(scene, ob, pchan_root, ctime);
+}
diff --git a/source/blender/depsgraph/intern/depsgraph_build.h 
b/source/blender/depsgraph/intern/depsgraph_build.h
index c2fb730..76c49a4 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.h
+++ b/source/blender/depsgraph/intern/depsgraph_build.h
@@ -136,7 +136,7 @@ struct DepsgraphNodeBuilder {
        void build_animdata(ID *id);
        OperationDepsNode *build_driver(ID *id, FCurve *fcurve);
        void build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, 
bConstraint *con);
-       void build_splineik_pose(Object *ob, bPoseChannel *pchan, bConstraint 
*con);
+       void build_splineik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, 
bConstraint *con);
        void build_rig(Scene *scene, Object *ob);
        void build_shapekeys(Key *key);
        void build_obdata_geom(Scene *scene, Object *ob);
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp 
b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
index 8835d47..4346e54 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cpp
@@ -536,7 +536,7 @@ void DepsgraphNodeBuilder::build_ik_pose(Scene *scene, 
Object *ob, bPoseChannel
 }
 
 /* Spline IK Eval Steps */
-void DepsgraphNodeBuilder::build_splineik_pose(Object *ob, bPoseChannel 
*pchan, bConstraint *con)
+void DepsgraphNodeBuilder::build_splineik_pose(Scene *scene, Object *ob, 
bPoseChannel *pchan, bConstraint *con)
 {
        bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
        
@@ -554,8 +554,8 @@ void DepsgraphNodeBuilder::build_splineik_pose(Object *ob, 
bPoseChannel *pchan,
        /* operation node for evaluating/running IK Solver
         * store the "root bone" of this chain in the solver, so it knows where 
to start
         */
-       add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, pchan->name,
-                          DEPSOP_TYPE_SIM, bind(BKE_pose_splineik_evaluate, 
_1, ob, rootchan),
+       add_operation_node(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name,
+                          DEPSOP_TYPE_SIM, bind(BKE_pose_splineik_evaluate, 
_1, scene, ob, rootchan),
                           deg_op_name_spline_ik_solver);
        // XXX: what sort of ID-data is needed?
 }
@@ -635,7 +635,7 @@ void DepsgraphNodeBuilder::build_rig(Scene *scene, Object 
*ob)
                                        break;
                                        
                                case CONSTRAINT_TYPE_SPLINEIK:
-                                       build_splineik_pose(ob, pchan, con);
+                                       build_splineik_pose(scene, ob, pchan, 
con);
                                        break;
                                        
                                default:
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp 
b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
index d00a48a..92f8f1d 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cpp
@@ -736,6 +736,23 @@ static bPoseChannel* ik_solver_rootchan_find(bPoseChannel 
*pchan,
        return rootchan;
 }
 
+/* TODO(sergey): Deduplicate with above. */
+static bPoseChannel* splineik_solver_rootchan_find(bPoseChannel *pchan,
+                                                   bSplineIKConstraint *data)
+{
+       bPoseChannel *rootchan = pchan;
+       if (rootchan) {
+               size_t segcount = 0;
+               while (rootchan->parent) {
+                       /* continue up chain, until we reach target number of 
items... */
+                       segcount++;
+                       if ((segcount == data->chainlen) || (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)
 {
@@ -801,22 +818,31 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *ob, 
bPoseChannel *pchan, bC
 void DepsgraphRelationBuilder::build_splineik_pose(Object *ob, bPoseChannel 
*pchan, bConstraint *con)
 {
        bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
-       
-       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);
+       bPoseChannel *rootchan = splineik_solver_rootchan_find(pchan, data);
+       OperationKey transforms_key = bone_transforms_key(ob, pchan);
+       OperationKey solver_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, 
rootchan->name, deg_op_name_spline_ik_solver);
        
        /* attach owner to IK Solver too 
         * - assume that owner is always part of chain 
         * - see notes on direction of rel below...
         */
-       add_relation(bone_key, solver_key, DEPSREL_TYPE_TRANSFORM, "Spline IK 
Solver Owner");
+       add_relation(transforms_key, solver_key, DEPSREL_TYPE_TRANSFORM, 
"Spline IK Solver Owner");
        
        /* attach path dependency to solver */
        if (data->tar) {
-               ComponentKey curve_path_key(&data->tar->id, 
DEPSNODE_TYPE_GEOMETRY);
-               add_relation(curve_path_key, solver_key, 
DEPSREL_TYPE_GEOMETRY_EVAL, "[Curve.Path -> Spline IK] DepsRel");
+               /* TODO(sergey): For until we'll store partial matricies in the 
depsgraph,
+                * we create dependency bewteen target object and pose eval 
component.
+                * See IK pose for a bit more information.
+                */
+               ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_GEOMETRY);
+               ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE);
+               add_relation(target_key, pose_key, 
DEPSREL_TYPE_TRANSFORM,"[Curve.Path -> Spline IK] DepsRel");
        }
-       
+
+       pchan->flag |= POSE_DONE;
+       OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, 
pchan->name, "Bone Final Transforms");
+       add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, 
"IK Solver Result");
+
        /* Walk to the chain's root */
        size_t segcount = 0;
        for (bPoseChannel *parchan = pchan->parent; parchan; parchan = 
parchan->parent) {
@@ -826,9 +852,15 @@ void DepsgraphRelationBuilder::build_splineik_pose(Object 
*ob, bPoseChannel *pch
                 * bone will ensure that users of this bone only
                 * grab the result with IK solver results...
                 */
-               ComponentKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, 
parchan->name);
-               add_relation(parent_key, solver_key, DEPSREL_TYPE_TRANSFORM, 
"Spline IK Solver Update");
-               
+               if (parchan != pchan) {
+                       OperationKey parent_key = bone_transforms_key(ob, 
parchan);
+                       add_relation(parent_key, solver_key, 
DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Update");
+               }
+               parchan->flag |= POSE_DONE;
+
+               OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, 
parchan->name, "Bone Final Transforms");
+               add_relation(solver_key, final_transforms_key, 
DEPSREL_TYPE_TRANSFORM, "IK Solver Result");
+
                /* continue up chain, until we reach target number of items... 
*/
                segcount++;
                if ((segcount == data->chainlen) || (segcount > 255)) break;  
/* 255 is weak */
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp 
b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
index 503bdaf..3b64ce6 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cpp
@@ -98,8 +98,6 @@ void BKE_animsys_eval_driver(EvaluationContext *eval_ctx, ID 
*id, FCurve *fcurve
        }
 }
 
-void BKE_pose_splineik_evaluate(EvaluationContext *eval_ctx, Object *ob, 
bPoseChannel *rootchan) {}
-
 void BKE_pose_rebuild_op(EvaluationContext *eval_ctx, Object *ob, bPose *pose)
 {
        bArmature *arm = (bArmature *)ob->data;
@@ -194,6 +192,16 @@ void BKE_pose_iktree_evaluate(EvaluationContext *eval_ctx,
        BIK_execute_tree(scene, ob, rootchan, ctime);
 }
 
+void BKE_pose_splineik_evaluate(EvaluationContext *eval_ctx,
+                                Scene *scene,
+                                Object *ob,
+                                bPoseChannel *rootchan)
+{
+       printf("%s on %s phan %s\n", __func__, ob->id.name, rootchan->name);
+       float ctime = BKE_scene_frame_get(scene); /* not accurate... */
+       BKE_splineik_execute_tree(scene, ob, rootchan, ctime);
+}
+
 void BKE_pose_eval_flush(EvaluationContext *eval_ctx,
                          Scene *scene,
                          Object *ob,
diff --git a/source/blender/depsgraph/intern/stubs.h 
b/source/blender/depsgraph/intern/stubs.h
index a95e236..92a6f5b 100644
--- a/source/blender/depsgraph/intern/stubs.h
+++ b/source/blender/depsgraph/intern/stubs.h
@@ -34,7 +34,7 @@ void BKE_pose_iktree_evaluate(struct EvaluationContext 
*eval_ctx,
                               Scene *scene,
                               Object *ob,
                               bPoseChannel *rootchan);
-void BKE_pose_splineik_evaluate(struct EvaluationContext *eval_ctx, Object 
*ob, bPoseChannel *rootchan);
+void BKE_pose_splineik_evaluate(struct EvaluationContext *eval_ctx, Scene 
*scene, Object *ob, bPoseChannel *rootchan);
 void BKE_pose_eval_bone(struct EvaluationContext *eval_ctx,
                         Scene *scene,
                         Object *ob,

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to