diff options
Diffstat (limited to 'source/blender/ikplugin/intern')
-rw-r--r-- | source/blender/ikplugin/intern/iksolver_plugin.c | 96 | ||||
-rw-r--r-- | source/blender/ikplugin/intern/itasc_plugin.cpp | 36 |
2 files changed, 72 insertions, 60 deletions
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index 7a96edeaf5f..41700b96acc 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -65,8 +65,8 @@ static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_t int a, t, segcount= 0, size, newsize, *oldparent, parent; /* find IK constraint, and validate it */ - for(con= pchan_tip->constraints.first; con; con= con->next) { - if(con->type==CONSTRAINT_TYPE_KINEMATIC) { + for (con= pchan_tip->constraints.first; con; con= con->next) { + if (con->type==CONSTRAINT_TYPE_KINEMATIC) { data=(bKinematicConstraint*)con->data; if (data->flag & CONSTRAINT_IK_AUTO) break; if (data->tar==NULL) continue; @@ -74,36 +74,36 @@ static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_t if ((con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF))==0 && (con->enforce != 0.0f)) break; } } - if(con==NULL) return; + if (con==NULL) return; /* exclude tip from chain? */ - if(!(data->flag & CONSTRAINT_IK_TIP)) + if (!(data->flag & CONSTRAINT_IK_TIP)) pchan_tip= pchan_tip->parent; /* Find the chain's root & count the segments needed */ - for (curchan = pchan_tip; curchan; curchan=curchan->parent){ + for (curchan = pchan_tip; curchan; curchan=curchan->parent) { pchan_root = curchan; curchan->flag |= POSE_CHAIN; // don't forget to clear this chanlist[segcount]=curchan; segcount++; - if(segcount==data->rootbone || segcount>255) break; // 255 is weak + if (segcount==data->rootbone || segcount>255) break; // 255 is weak } if (!segcount) return; /* setup the chain data */ /* we make tree-IK, unless all existing targets are in this chain */ - for(tree= pchan_root->iktree.first; tree; tree= tree->next) { - for(target= tree->targets.first; target; target= target->next) { + for (tree= pchan_root->iktree.first; tree; tree= tree->next) { + for (target= tree->targets.first; target; target= target->next) { curchan= tree->pchan[target->tip]; - if(curchan->flag & POSE_CHAIN) + if (curchan->flag & POSE_CHAIN) curchan->flag &= ~POSE_CHAIN; else break; } - if(target) break; + if (target) break; } /* create a target */ @@ -111,7 +111,7 @@ static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_t target->con= con; pchan_tip->flag &= ~POSE_CHAIN; - if(tree==NULL) { + if (tree==NULL) { /* make new tree */ tree= MEM_callocN(sizeof(PoseTree), "posetree"); @@ -123,7 +123,7 @@ static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_t tree->pchan= MEM_callocN(segcount*sizeof(void*), "ik tree pchan"); tree->parent= MEM_callocN(segcount*sizeof(int), "ik tree parent"); - for(a=0; a<segcount; a++) { + for (a=0; a<segcount; a++) { tree->pchan[a]= chanlist[segcount-a-1]; tree->parent[a]= a-1; } @@ -144,19 +144,19 @@ static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_t for (;t<tree->totchannel && tree->pchan[t]!=chanlist[segcount-a-1];t++); if (t>=tree->totchannel) break; - for(; a<size && t<tree->totchannel && tree->pchan[t]==chanlist[segcount-a-1]; a++, t++); + for (; a<size && t<tree->totchannel && tree->pchan[t]==chanlist[segcount-a-1]; a++, t++); } segcount= segcount-a; target->tip= tree->totchannel + segcount - 1; if (segcount > 0) { - for(parent = a - 1; parent < tree->totchannel; parent++) - if(tree->pchan[parent] == chanlist[segcount-1]->parent) + for (parent = a - 1; parent < tree->totchannel; parent++) + if (tree->pchan[parent] == chanlist[segcount-1]->parent) break; /* shouldn't happen, but could with dependency cycles */ - if(parent == tree->totchannel) + if (parent == tree->totchannel) parent = a - 1; /* resize array */ @@ -172,7 +172,7 @@ static void initialize_posetree(struct Object *UNUSED(ob), bPoseChannel *pchan_t MEM_freeN(oldparent); /* add new pose channels at the end, in reverse order */ - for(a=0; a<segcount; a++) { + for (a=0; a<segcount; a++) { tree->pchan[tree->totchannel+a]= chanlist[segcount-a-1]; tree->parent[tree->totchannel+a]= tree->totchannel+a-1; } @@ -256,20 +256,20 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) iktree= MEM_mallocN(sizeof(void*)*tree->totchannel, "ik tree"); - for(a=0; a<tree->totchannel; a++) { + for (a=0; a<tree->totchannel; a++) { pchan= tree->pchan[a]; bone= pchan->bone; /* set DoF flag */ flag= 0; - if(!(pchan->ikflag & BONE_IK_NO_XDOF) && !(pchan->ikflag & BONE_IK_NO_XDOF_TEMP)) + if (!(pchan->ikflag & BONE_IK_NO_XDOF) && !(pchan->ikflag & BONE_IK_NO_XDOF_TEMP)) flag |= IK_XDOF; - if(!(pchan->ikflag & BONE_IK_NO_YDOF) && !(pchan->ikflag & BONE_IK_NO_YDOF_TEMP)) + if (!(pchan->ikflag & BONE_IK_NO_YDOF) && !(pchan->ikflag & BONE_IK_NO_YDOF_TEMP)) flag |= IK_YDOF; - if(!(pchan->ikflag & BONE_IK_NO_ZDOF) && !(pchan->ikflag & BONE_IK_NO_ZDOF_TEMP)) + if (!(pchan->ikflag & BONE_IK_NO_ZDOF) && !(pchan->ikflag & BONE_IK_NO_ZDOF_TEMP)) flag |= IK_ZDOF; - if(tree->stretch && (pchan->ikstretch > 0.0f)) { + if (tree->stretch && (pchan->ikstretch > 0.0f)) { flag |= IK_TRANS_YDOF; hasstretch = 1; } @@ -277,7 +277,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) seg= iktree[a]= IK_CreateSegment(flag); /* find parent */ - if(a == 0) + if (a == 0) parent= NULL; else parent= iktree[tree->parent[a]]; @@ -334,7 +334,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) IK_SetStiffness(seg, IK_Y, pchan->stiffness[1]); IK_SetStiffness(seg, IK_Z, pchan->stiffness[2]); - if(tree->stretch && (pchan->ikstretch > 0.0f)) { + if (tree->stretch && (pchan->ikstretch > 0.0f)) { float ikstretch = pchan->ikstretch*pchan->ikstretch; IK_SetStiffness(seg, IK_TRANS_Y, MIN2(1.0f-ikstretch, 0.99f)); IK_SetLimit(seg, IK_TRANS_Y, 0.001, 1e10); @@ -377,10 +377,10 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) copy_m3_m4(goalrot, goal); /* same for pole vector target */ - if(data->poletar) { + if (data->poletar) { get_constraint_target_matrix(scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); - if(data->flag & CONSTRAINT_IK_SETANGLE) { + if (data->flag & CONSTRAINT_IK_SETANGLE) { /* don't solve IK when we are setting the pole angle */ break; } @@ -395,7 +395,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) resultblend= 1; resultinf= target->con->enforce; - if(data->flag & CONSTRAINT_IK_GETANGLE) { + if (data->flag & CONSTRAINT_IK_GETANGLE) { poleangledata= data; data->flag &= ~CONSTRAINT_IK_GETANGLE; } @@ -429,14 +429,14 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) iktarget= iktree[target->tip]; - if(data->weight != 0.0f) { - if(poleconstrain) + if (data->weight != 0.0f) { + if (poleconstrain) IK_SolverSetPoleVectorConstraint(solver, iktarget, goalpos, polepos, data->poleangle, (poleangledata == data)); IK_SolverAddGoal(solver, iktarget, goalpos, data->weight); } - if((data->flag & CONSTRAINT_IK_ROT) && (data->orientweight != 0.0f)) - if((data->flag & CONSTRAINT_IK_AUTO)==0) + if ((data->flag & CONSTRAINT_IK_ROT) && (data->orientweight != 0.0f)) + if ((data->flag & CONSTRAINT_IK_AUTO)==0) IK_SolverAddGoalOrientation(solver, iktarget, goalrot, data->orientweight); } @@ -444,27 +444,27 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) /* solve */ IK_Solve(solver, 0.0f, tree->iterations); - if(poleangledata) + if (poleangledata) poleangledata->poleangle= IK_SolverGetPoleAngle(solver); IK_FreeSolver(solver); /* gather basis changes */ tree->basis_change= MEM_mallocN(sizeof(float[3][3])*tree->totchannel, "ik basis change"); - if(hasstretch) + if (hasstretch) ikstretch= MEM_mallocN(sizeof(float)*tree->totchannel, "ik stretch"); - for(a=0; a<tree->totchannel; a++) { + for (a=0; a<tree->totchannel; a++) { IK_GetBasisChange(iktree[a], tree->basis_change[a]); - if(hasstretch) { + if (hasstretch) { /* have to compensate for scaling received from parent */ float parentstretch, stretch; pchan= tree->pchan[a]; parentstretch= (tree->parent[a] >= 0)? ikstretch[tree->parent[a]]: 1.0f; - if(tree->stretch && (pchan->ikstretch > 0.0f)) { + if (tree->stretch && (pchan->ikstretch > 0.0f)) { float trans[3], length; IK_GetTranslationChange(iktree[a], trans); @@ -482,7 +482,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) mul_v3_fl(tree->basis_change[a][2], stretch); } - if(resultblend && resultinf!=1.0f) { + if (resultblend && resultinf!=1.0f) { unit_m3(identity); blend_m3_m3m3(tree->basis_change[a], identity, tree->basis_change[a], resultinf); @@ -492,15 +492,15 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) } MEM_freeN(iktree); - if(ikstretch) MEM_freeN(ikstretch); + if (ikstretch) MEM_freeN(ikstretch); } static void free_posetree(PoseTree *tree) { BLI_freelistN(&tree->targets); - if(tree->pchan) MEM_freeN(tree->pchan); - if(tree->parent) MEM_freeN(tree->parent); - if(tree->basis_change) MEM_freeN(tree->basis_change); + if (tree->pchan) MEM_freeN(tree->pchan); + if (tree->parent) MEM_freeN(tree->parent); + if (tree->basis_change) MEM_freeN(tree->basis_change); MEM_freeN(tree); } @@ -511,8 +511,8 @@ void iksolver_initialize_tree(struct Scene *UNUSED(scene), struct Object *ob, fl { bPoseChannel *pchan; - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if(pchan->constflag & PCHAN_HAS_IK) // flag is set on editing constraints + for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + if (pchan->constflag & PCHAN_HAS_IK) // flag is set on editing constraints initialize_posetree(ob, pchan); // will attach it to root! } ob->pose->flag &= ~POSE_WAS_REBUILT; @@ -520,7 +520,7 @@ void iksolver_initialize_tree(struct Scene *UNUSED(scene), struct Object *ob, fl void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime) { - while(pchan->iktree.first) { + while (pchan->iktree.first) { PoseTree *tree= pchan->iktree.first; int a; @@ -529,8 +529,8 @@ void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPose return; /* 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 + for (a=0; a<tree->totchannel; a++) { + if (!(tree->pchan[a]->flag & POSE_DONE)) // successive trees can set the flag where_is_pose_bone(scene, ob, tree->pchan[a], ctime, 1); // tell blender that this channel was controlled by IK, it's cleared on each where_is_pose() tree->pchan[a]->flag |= POSE_CHAIN; @@ -540,11 +540,11 @@ void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPose /* 6. apply the differences to the channels, * we need to calculate the original differences first */ - for(a=0; a<tree->totchannel; a++) { + for (a=0; a<tree->totchannel; a++) { make_dmats(tree->pchan[a]); } - for(a=0; a<tree->totchannel; a++) { + for (a=0; a<tree->totchannel; a++) { /* sets POSE_DONE */ where_is_ik_bone(tree->pchan[a], tree->basis_change[a]); } diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 5385366f075..72370158723 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -430,7 +430,8 @@ static double EulerAngleFromMatrix(const KDL::Rotation& R, int axis) if (axis == 0) return -KDL::atan2(R(1,2), R(2,2)); else if(axis == 1) return KDL::atan2(-R(0,2), t); else return -KDL::atan2(R(0,1), R(0,0)); - } else { + } + else { if (axis == 0) return -KDL::atan2(-R(2,1), R(1,1)); else if(axis == 1) return KDL::atan2(-R(0,2), t); else return 0.0f; @@ -476,7 +477,8 @@ static void GetEulerXZY(const KDL::Rotation& R, double& X,double& Z,double& Y) X = -KDL::sign(R(0,1)) * KDL::atan2(R(1,2), R(1,0)); Z = -KDL::sign(R(0,1)) * KDL::PI / 2; Y = 0.0; - } else { + } + else { X = KDL::atan2(R(2,1), R(1,1)); Z = KDL::atan2(-R(0,1), KDL::sqrt( KDL::sqr(R(0,0)) + KDL::sqr(R(0,2)))); Y = KDL::atan2(R(0,2), R(0,0)); @@ -489,7 +491,8 @@ static void GetEulerXYZ(const KDL::Rotation& R, double& X,double& Y,double& Z) X = KDL::sign(R(0,2)) * KDL::atan2(-R(1,0), R(1,1)); Y = KDL::sign(R(0,2)) * KDL::PI / 2; Z = 0.0; - } else { + } + else { X = KDL::atan2(-R(1,2), R(2,2)); Y = KDL::atan2(R(0,2), KDL::sqrt( KDL::sqr(R(0,0)) + KDL::sqr(R(0,1)))); Z = KDL::atan2(-R(0,1), R(0,0)); @@ -691,7 +694,8 @@ static bool copypose_callback(const iTaSC::Timestamp& timestamp, iTaSC::Constrai values->action = iTaSC::ACT_ALPHA; values++; } - } else { + } + else { if (iktarget->controlType & iTaSC::CopyPose::CTL_POSITION) { // update error values->alpha = condata->weight; @@ -745,7 +749,8 @@ static bool distance_callback(const iTaSC::Timestamp& timestamp, iTaSC::Constrai // update weight according to mode if (iktarget->blenderConstraint->flag & CONSTRAINT_OFF) { values->alpha = 0.0; - } else { + } + else { switch (condata->mode) { case LIMITDIST_INSIDE: values->alpha = (values->values[0].y > condata->dist) ? condata->weight : 0.0; @@ -996,7 +1001,8 @@ static void convert_pose(IK_Scene *ikscene) if (pchan->parent) { unit_m4(bmat); mul_m4_m4m3(bmat, pchan->parent->pose_mat, bone->bone_mat); - } else { + } + else { copy_m4_m4(bmat, bone->arm_mat); } invert_m4_m4(rmat, bmat); @@ -1076,7 +1082,8 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) if (!ikparam) { // you must have our own copy ikparam = &DefIKParam; - } else if (ingame) { + } + 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 @@ -1120,7 +1127,8 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) // in the GE, set the initial joint angle to match the current pose // this will update the jointArray in ikscene convert_pose(ikscene); - } else { + } + else { // in Blender, the rest pose is always 0 for joints rest_pose(ikscene); } @@ -1393,7 +1401,8 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) // move to the tail and scale to get rest pose of armature base copy_v3_v3(baseFrame[3], pchan->bone->arm_tail); invert_m4_m4(invBaseFrame, baseFrame); - } else { + } + else { unit_m4(invBaseFrame); } // finally add the constraint @@ -1538,7 +1547,8 @@ static void execute_scene(Scene* blscene, IK_Scene* ikscene, bItasc* ikparam, fl ikchan->pchan->flag |= (POSE_DONE|POSE_CHAIN); ikchan->jointValid = 0; } - } else { + } + else { // 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)) @@ -1589,7 +1599,8 @@ static void execute_scene(Scene* blscene, IK_Scene* ikscene, bItasc* ikparam, fl // the cache is empty before this time, reiterate if (ikparam->flag & ITASC_INITIAL_REITERATION) reiterate = true; - } else { + } + else { // can take the cache as a start point. sts -= cts; timestep = sts/1000.0; @@ -1780,7 +1791,8 @@ void itasc_update_param(struct bPose *pose) ikscene->scene->setParam(iTaSC::Scene::MAX_TIMESTEP, ikparam->maxstep); ikscene->solver->setParam(iTaSC::Solver::DLS_QMAX, ikparam->maxvel); ikscene->armature->setControlParameter(CONSTRAINT_ID_ALL, iTaSC::Armature::ID_JOINT, iTaSC::ACT_FEEDBACK, ikparam->feedback); - } else { + } + else { // in animation mode timestep is 1s by convention => // qmax becomes radiant and feedback becomes fraction of error gap corrected in one iteration ikscene->scene->setParam(iTaSC::Scene::MIN_TIMESTEP, 1.0); |