diff options
Diffstat (limited to 'source/blender/ikplugin')
-rw-r--r-- | source/blender/ikplugin/BIK_api.h | 5 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/ikplugin_api.c | 8 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/ikplugin_api.h | 7 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/iksolver_plugin.c | 14 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/iksolver_plugin.h | 7 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/itasc_plugin.cpp | 73 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/itasc_plugin.h | 4 |
7 files changed, 51 insertions, 67 deletions
diff --git a/source/blender/ikplugin/BIK_api.h b/source/blender/ikplugin/BIK_api.h index 3f53e24f24a..07a223b738e 100644 --- a/source/blender/ikplugin/BIK_api.h +++ b/source/blender/ikplugin/BIK_api.h @@ -43,6 +43,7 @@ struct bPoseChannel; struct bPose; struct Scene; struct bConstraint; +struct Depsgraph; enum BIK_ParamType { BIK_PARAM_TYPE_FLOAT = 0, @@ -61,8 +62,8 @@ struct BIK_ParamValue { }; typedef struct BIK_ParamValue BIK_ParamValue; -void BIK_initialize_tree(struct Scene *scene, struct Object *ob, float ctime); -void BIK_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); +void BIK_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); +void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); void BIK_release_tree(struct Scene *scene, struct Object *ob, float ctime); void BIK_clear_data(struct bPose *pose); void BIK_clear_cache(struct bPose *pose); diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c index 00fb5768d79..d2681440177 100644 --- a/source/blender/ikplugin/intern/ikplugin_api.c +++ b/source/blender/ikplugin/intern/ikplugin_api.c @@ -89,20 +89,20 @@ static IKPlugin *get_plugin(bPose *pose) /*----------------------------------------*/ /* Plugin API */ -void BIK_initialize_tree(Scene *scene, Object *ob, float ctime) +void BIK_initialize_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); if (plugin && plugin->initialize_tree_func) - plugin->initialize_tree_func(scene, ob, ctime); + plugin->initialize_tree_func(depsgraph, scene, ob, ctime); } -void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) +void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); if (plugin && plugin->execute_tree_func) - plugin->execute_tree_func(scene, ob, pchan, ctime); + plugin->execute_tree_func(depsgraph, scene, ob, pchan, ctime); } void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) diff --git a/source/blender/ikplugin/intern/ikplugin_api.h b/source/blender/ikplugin/intern/ikplugin_api.h index 0b4df11de60..139a50f44f0 100644 --- a/source/blender/ikplugin/intern/ikplugin_api.h +++ b/source/blender/ikplugin/intern/ikplugin_api.h @@ -38,14 +38,15 @@ extern "C" { #endif +struct Depsgraph; struct Object; -struct bPoseChannel; struct Scene; +struct bPoseChannel; struct IKPlugin { - void (*initialize_tree_func)(struct Scene *scene, struct Object *ob, float ctime); - void (*execute_tree_func)(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); + void (*initialize_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); + void (*execute_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); void (*release_tree_func)(struct Scene *scene, struct Object *ob, float ctime); void (*remove_armature_func)(struct bPose *pose); void (*clear_cache)(struct bPose *pose); diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index 616e9a723f6..9248d85c809 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -252,7 +252,7 @@ static void where_is_ik_bone(bPoseChannel *pchan, float ik_mat[3][3]) // nr = /* called from within the core BKE_pose_where_is loop, all animsystems and constraints * were executed & assigned. Now as last we do an IK pass */ -static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) +static void execute_posetree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, PoseTree *tree) { float R_parmat[3][3], identity[3][3]; float iR_parmat[3][3]; @@ -394,7 +394,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) /* 1.0=ctime, we pass on object for auto-ik (owner-type here is object, even though * strictly speaking, it is a posechannel) */ - BKE_constraint_target_matrix_get(scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); + BKE_constraint_target_matrix_get(depsgraph, scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); /* and set and transform goal */ mul_m4_m4m4(goal, goalinv, rootmat); @@ -405,7 +405,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) /* same for pole vector target */ if (data->poletar) { - BKE_constraint_target_matrix_get(scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); + BKE_constraint_target_matrix_get(depsgraph, scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); if (data->flag & CONSTRAINT_IK_SETANGLE) { /* don't solve IK when we are setting the pole angle */ @@ -534,7 +534,7 @@ static void free_posetree(PoseTree *tree) ///---------------------------------------- /// Plugin API for legacy iksolver -void iksolver_initialize_tree(struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime)) +void iksolver_initialize_tree(struct Depsgraph *UNUSED(depsgraph), struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime)) { bPoseChannel *pchan; @@ -545,7 +545,7 @@ void iksolver_initialize_tree(struct Scene *UNUSED(scene), struct Object *ob, fl ob->pose->flag &= ~POSE_WAS_REBUILT; } -void iksolver_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) +void iksolver_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { while (pchan_root->iktree.first) { PoseTree *tree = pchan_root->iktree.first; @@ -558,13 +558,13 @@ void iksolver_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan /* 4. walk over the tree for regular solving */ for (a = 0; a < tree->totchannel; a++) { if (!(tree->pchan[a]->flag & POSE_DONE)) // successive trees can set the flag - BKE_pose_where_is_bone(scene, ob, tree->pchan[a], ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, tree->pchan[a], ctime, 1); /* tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() */ tree->pchan[a]->flag |= POSE_CHAIN; } /* 5. execute the IK solver */ - execute_posetree(scene, ob, tree); + execute_posetree(depsgraph, scene, ob, tree); /* 6. apply the differences to the channels, * we need to calculate the original differences first */ diff --git a/source/blender/ikplugin/intern/iksolver_plugin.h b/source/blender/ikplugin/intern/iksolver_plugin.h index bb12c83d885..cce9511630f 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.h +++ b/source/blender/ikplugin/intern/iksolver_plugin.h @@ -40,8 +40,11 @@ extern "C" { #endif -void iksolver_initialize_tree(struct Scene *scene, struct Object *ob, float ctime); -void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); +void iksolver_initialize_tree( + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); +void iksolver_execute_tree( + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, + struct bPoseChannel *pchan_root, float ctime); #ifdef __cplusplus } diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 17f9cd5bc7a..4a71b36bfef 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -90,6 +90,7 @@ typedef void (*ErrorCallback)(const iTaSC::ConstraintValues *values, unsigned in // one structure for each target in the scene struct IK_Target { + struct Depsgraph *bldepsgraph; struct Scene *blscene; iTaSC::MovingFrame* target; iTaSC::ConstraintSet* constraint; @@ -107,6 +108,7 @@ struct IK_Target { float eeRest[4][4]; //end effector initial pose relative to armature IK_Target() { + bldepsgraph = NULL; blscene = NULL; target = NULL; constraint = NULL; @@ -157,6 +159,7 @@ struct IK_Channel { }; struct IK_Scene { + struct Depsgraph *bldepsgraph; struct Scene *blscene; IK_Scene* next; int numchan; // number of channel in pchan @@ -177,6 +180,7 @@ struct IK_Scene { std::vector<IK_Target*> targets; IK_Scene() { + bldepsgraph = NULL; blscene = NULL; next = NULL; channels = NULL; @@ -550,7 +554,7 @@ static bool target_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Fram bConstraint *constraint = (bConstraint *)target->blenderConstraint; float tarmat[4][4]; - BKE_constraint_target_matrix_get(target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0); + BKE_constraint_target_matrix_get(target->bldepsgraph, target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0); // rootmat contains the target pose in world coordinate // if enforce is != 1.0, blend the target position with the end effector position @@ -619,7 +623,7 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& IK_Channel &rootchan = ikscene->channels[0]; // get polar target matrix in world space - BKE_constraint_target_matrix_get(ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0); + BKE_constraint_target_matrix_get(ikscene->bldepsgraph, ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0); // convert to armature space mul_m4_m4m4(polemat, imat, mat); // get the target in world space (was computed before as target object are defined before base object) @@ -863,7 +867,7 @@ static bool joint_callback(const iTaSC::Timestamp& timestamp, iTaSC::ConstraintV } // build array of joint corresponding to IK chain -static int convert_channels(IK_Scene *ikscene, PoseTree *tree, float ctime) +static int convert_channels(struct Depsgraph *depsgraph, IK_Scene *ikscene, PoseTree *tree, float ctime) { IK_Channel *ikchan; bPoseChannel *pchan; @@ -880,7 +884,7 @@ static int convert_channels(IK_Scene *ikscene, PoseTree *tree, float ctime) // this is because some of the pose data (e.g. pose head) don't have corresponding // joint angles and can't be applied to the iTaSC armature dynamically if (!(pchan->flag & POSE_DONE)) - BKE_pose_where_is_bone(ikscene->blscene, ikscene->blArmature, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, ikscene->blscene, ikscene->blArmature, pchan, ctime, 1); // tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() pchan->flag |= (POSE_DONE | POSE_CHAIN); @@ -1056,7 +1060,7 @@ static void BKE_pose_rest(IK_Scene *ikscene) } } -static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime) +static IK_Scene *convert_tree(struct Depsgraph *depsgraph, Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime) { PoseTree *tree = (PoseTree *)pchan->iktree.first; PoseTarget *target; @@ -1068,12 +1072,11 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f IK_Scene *ikscene; IK_Channel *ikchan; KDL::Frame initPose; - KDL::Rotation boneRot; Bone *bone; int a, numtarget; unsigned int t; float length; - bool ret = true, ingame; + bool ret = true; double *rot; float start[3]; @@ -1082,6 +1085,7 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f ikscene = new IK_Scene; ikscene->blscene = blscene; + ikscene->bldepsgraph = depsgraph; arm = new iTaSC::Armature(); scene = new iTaSC::Scene(); ikscene->channels = new IK_Channel[tree->totchannel]; @@ -1089,26 +1093,13 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f ikscene->armature = arm; ikscene->scene = scene; ikparam = (bItasc *)ob->pose->ikparam; - ingame = (ob->pose->flag & POSE_GAME_ENGINE); + if (!ikparam) { // you must have our own copy ikparam = &DefIKParam; } - else if (ingame) { - // tweak the param when in game to have efficient stepping - // using fixed substep is not effecient since frames in the GE are often - // shorter than in animation => move to auto step automatically and set - // the target substep duration via min/max - if (!(ikparam->flag & ITASC_AUTO_STEP)) { - float timestep = blscene->r.frs_sec_base / blscene->r.frs_sec; - if (ikparam->numstep > 0) - timestep /= ikparam->numstep; - // with equal min and max, the algorythm will take this step and the indicative substep most of the time - ikparam->minstep = ikparam->maxstep = timestep; - ikparam->flag |= ITASC_AUTO_STEP; - } - } - if ((ikparam->flag & ITASC_SIMULATION) && !ingame) + + if (ikparam->flag & ITASC_SIMULATION) // no cache in animation mode ikscene->cache = new iTaSC::Cache(); @@ -1134,16 +1125,9 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f std::vector<double> weights; double weight[3]; // build the array of joints corresponding to the IK chain - convert_channels(ikscene, tree, ctime); - if (ingame) { - // in the GE, set the initial joint angle to match the current pose - // this will update the jointArray in ikscene - convert_pose(ikscene); - } - else { - // in Blender, the rest pose is always 0 for joints - BKE_pose_rest(ikscene); - } + convert_channels(depsgraph, ikscene, tree, ctime); + // in Blender, the rest pose is always 0 for joints + BKE_pose_rest(ikscene); rot = ikscene->jointArray(0); for (a = 0, ikchan = ikscene->channels; a < tree->totchannel; ++a, ++ikchan) { @@ -1439,6 +1423,7 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f for (t = 0; t < ikscene->targets.size(); t++) { IK_Target *iktarget = ikscene->targets[t]; iktarget->blscene = blscene; + iktarget->bldepsgraph = depsgraph; condata = (bKinematicConstraint *)iktarget->blenderConstraint->data; pchan = tree->pchan[iktarget->channel]; unsigned int controltype, bonecnt; @@ -1526,7 +1511,7 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f return ikscene; } -static void create_scene(Scene *scene, Object *ob, float ctime) +static void create_scene(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { bPoseChannel *pchan; @@ -1537,7 +1522,7 @@ static void create_scene(Scene *scene, Object *ob, float ctime) if (tree) { IK_Data *ikdata = get_ikdata(ob->pose); // convert tree in iTaSC::Scene - IK_Scene *ikscene = convert_tree(scene, ob, pchan, ctime); + IK_Scene *ikscene = convert_tree(depsgraph, scene, ob, pchan, ctime); if (ikscene) { ikscene->next = ikdata->first; ikdata->first = ikscene; @@ -1576,7 +1561,7 @@ static int init_scene(Object *ob) return 0; } -static void execute_scene(Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime) +static void execute_scene(struct Depsgraph *depsgraph, Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime) { int i; IK_Channel *ikchan; @@ -1592,7 +1577,7 @@ static void execute_scene(Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, fl // in animation mode, we must get the bone position from action and constraints for (i = 0, ikchan = ikscene->channels; i < ikscene->numchan; i++, ++ikchan) { if (!(ikchan->pchan->flag & POSE_DONE)) - BKE_pose_where_is_bone(blscene, ikscene->blArmature, ikchan->pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, blscene, ikscene->blArmature, ikchan->pchan, ctime, 1); // tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() ikchan->pchan->flag |= (POSE_DONE | POSE_CHAIN); ikchan->jointValid = 0; @@ -1744,7 +1729,7 @@ static void execute_scene(Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, fl //--------------------------------------------------- // plugin interface // -void itasc_initialize_tree(struct Scene *scene, Object *ob, float ctime) +void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, float ctime) { bPoseChannel *pchan; int count = 0; @@ -1764,13 +1749,13 @@ void itasc_initialize_tree(struct Scene *scene, Object *ob, float ctime) // if at least one tree, create the scenes from the PoseTree stored in the channels // postpone until execute_tree: this way the pose constraint are included if (count) - create_scene(scene, ob, ctime); + create_scene(depsgraph, scene, ob, ctime); itasc_update_param(ob->pose); // make sure we don't rebuilt until the user changes something important ob->pose->flag &= ~POSE_WAS_REBUILT; } -void itasc_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) +void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { if (ob->pose->ikdata) { IK_Data *ikdata = (IK_Data *)ob->pose->ikdata; @@ -1781,13 +1766,7 @@ void itasc_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan_ro for (IK_Scene *ikscene = ikdata->first; ikscene; ikscene = ikscene->next) { if (ikscene->channels[0].pchan == pchan_root) { float timestep = scene->r.frs_sec_base / scene->r.frs_sec; - if (ob->pose->flag & POSE_GAME_ENGINE) { - timestep = ob->pose->ctime; - // limit the timestep to avoid excessive number of iteration - if (timestep > 0.2f) - timestep = 0.2f; - } - execute_scene(scene, ikscene, ikparam, ctime, timestep); + execute_scene(depsgraph, scene, ikscene, ikparam, ctime, timestep); break; } } diff --git a/source/blender/ikplugin/intern/itasc_plugin.h b/source/blender/ikplugin/intern/itasc_plugin.h index bbdb0687eba..2853ae095db 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.h +++ b/source/blender/ikplugin/intern/itasc_plugin.h @@ -40,8 +40,8 @@ extern "C" { #endif -void itasc_initialize_tree(struct Scene *scene, struct Object *ob, float ctime); -void itasc_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); +void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); +void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); void itasc_release_tree(struct Scene *scene, struct Object *ob, float ctime); void itasc_clear_data(struct bPose *pose); void itasc_clear_cache(struct bPose *pose); |