void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime) { while(pchan->iktree.first) { PoseTree *tree= pchan->iktree.first; int a; /* stop on the first tree that isn't a standard IK chain */ if (tree->type != CONSTRAINT_TYPE_KINEMATIC) 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 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; } /* 5. execute the IK solver */ execute_posetree(scene, ob, tree); /* 6. apply the differences to the channels, we need to calculate the original differences first */ for(a=0; a<tree->totchannel; a++) make_dmats(tree->pchan[a]); for(a=0; a<tree->totchannel; a++) /* sets POSE_DONE */ where_is_ik_bone(tree->pchan[a], tree->basis_change[a]); /* 7. and free */ BLI_remlink(&pchan->iktree, tree); free_posetree(tree); } }
void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan) { bPoseChannel *parchan = NULL; bPose *pose = ob_arm->pose; pchan = get_pose_channel(pose, bone->name); if (!pchan) return; parchan = pchan->parent; enable_fcurves(ob_arm->adt->action, bone->name); std::vector<float>::iterator it; for (it = frames.begin(); it != frames.end(); it++) { float mat[4][4], ipar[4][4]; float ctime = BKE_frame_to_ctime(scene, *it); BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM); where_is_pose_bone(scene, ob_arm, pchan, ctime, 1); // compute bone local mat if (bone->parent) { invert_m4_m4(ipar, parchan->pose_mat); mult_m4_m4m4(mat, ipar, pchan->pose_mat); } else copy_m4_m4(mat, pchan->pose_mat); switch (type) { case 0: mat4_to_eul(v, mat); break; case 1: mat4_to_size(v, mat); break; case 2: copy_v3_v3(v, mat[3]); break; } v += 3; } enable_fcurves(ob_arm->adt->action, NULL); }
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames , Object * ob_arm, Bone *bone , const std::string& anim_id) { COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT; std::string source_id = anim_id + get_semantic_suffix(semantic); COLLADASW::Float4x4Source source(mSW); source.setId(source_id); source.setArrayId(source_id + ARRAY_ID_SUFFIX); source.setAccessorCount(frames.size()); source.setAccessorStride(16); COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); add_source_parameters(param, semantic, false, NULL, true); source.prepareToAppendValues(); bPoseChannel *parchan = NULL; bPoseChannel *pchan = NULL; bPose *pose = ob_arm->pose; pchan = get_pose_channel(pose, bone->name); if (!pchan) return ""; parchan = pchan->parent; enable_fcurves(ob_arm->adt->action, bone->name); std::vector<float>::iterator it; int j = 0; for (it = frames.begin(); it != frames.end(); it++) { float mat[4][4], ipar[4][4]; float ctime = BKE_frame_to_ctime(scene, *it); BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM); where_is_pose_bone(scene, ob_arm, pchan, ctime, 1); // compute bone local mat if (bone->parent) { invert_m4_m4(ipar, parchan->pose_mat); mult_m4_m4m4(mat, ipar, pchan->pose_mat); } else copy_m4_m4(mat, pchan->pose_mat); UnitConverter converter; float outmat[4][4]; converter.mat4_to_dae(outmat,mat); source.appendValues(outmat); j++; } enable_fcurves(ob_arm->adt->action, NULL); source.finish(); return source_id; }