diff options
author | Sukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com> | 2011-08-03 23:12:18 +0400 |
---|---|---|
committer | Sukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com> | 2011-08-03 23:12:18 +0400 |
commit | cbdc67e2e81cb136a0dca2218dd0ccb6ecc557ca (patch) | |
tree | 4e3f83569c04a7788ec20ae2f065a0f9e04cb2eb /source/blender | |
parent | 0031950a746d6a1b632e6c57359432803e8871c9 (diff) |
Find all key frames for baked animation export.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/collada/AnimationExporter.cpp | 53 | ||||
-rw-r--r-- | source/blender/collada/AnimationExporter.h | 6 |
2 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 2f92d9212a9..5a5ec4fea2d 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -61,6 +61,13 @@ void AnimationExporter::exportAnimations(Scene *sce) bool isMatAnim = false; if(ob->adt && ob->adt->action) { + if ( ob->type == OB_ARMATURE ) + { + bArmature *arm = (bArmature*)ob->data; + for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) + bake_bone_animation(ob, bone); + + } fcu = (FCurve*)ob->adt->action->curves.first; while (fcu) { transformName = extract_transform_name( fcu->rna_path ); @@ -318,6 +325,17 @@ void AnimationExporter::exportAnimations(Scene *sce) closeAnimation(); } + void AnimationExporter::bake_bone_animation(Object *ob_arm, Bone *bone) + { + if (!ob_arm->adt) + return; + + sample_and_bake_bone_animation(ob_arm, bone); + + for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) + bake_bone_animation(ob_arm, child); + } + void AnimationExporter::write_bone_animation(Object *ob_arm, Bone *bone) { if (!ob_arm->adt) @@ -334,6 +352,22 @@ void AnimationExporter::exportAnimations(Scene *sce) write_bone_animation(ob_arm, child); } + void AnimationExporter::sample_and_bake_bone_animation(Object *ob_arm, Bone *bone) + { + bArmature *arm = (bArmature*)ob_arm->data; + int flag = arm->flag; + std::vector<float> fra; + char prefix[256]; + + BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name); + + bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name); + if (!pchan) + return; + + find_all_frames(ob_arm, fra); + } + void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type) { bArmature *arm = (bArmature*)ob_arm->data; @@ -920,6 +954,25 @@ void AnimationExporter::exportAnimations(Scene *sce) return dot ? (dot + 1) : rna_path; } + void AnimationExporter::find_all_frames(Object *ob, std::vector<float> &fra) + { + FCurve *fcu= (FCurve*)ob->adt->action->curves.first; + std::vector<float> keys; + for (unsigned int i = 0; i < fcu->totvert; i++) { + float f = fcu->bezt[i].vec[1][0]; // + if (std::find(keys.begin(), keys.end(), f) == keys.end()) + keys.push_back(f); + } + + std::sort(keys.begin(), keys.end()); + + for ( float fAll = *(keys.begin()) ; fAll != *(keys.end()) ; fAll+=1.0f ) + { + fra.push_back(fAll); + } + return; + + } void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name) { FCurve *fcu= (FCurve*)ob->adt->action->curves.first; diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index 3e3150cd8ef..388d7dbb24d 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -96,10 +96,14 @@ protected: void dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material *ma = NULL); + void bake_bone_animation(Object *ob_arm, Bone *bone); + void write_bone_animation(Object *ob_arm, Bone *bone); void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type); + void sample_and_bake_bone_animation(Object *ob_arm, Bone *bone); + void sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pChan); // dae_bone_animation -> add_bone_animation @@ -134,6 +138,8 @@ protected: std::string get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); void find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name); + + void find_all_frames(Object *ob, std::vector<float> &fra); void find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode); |