Revision: 39004
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39004
Author:   phabtar
Date:     2011-08-03 19:12:18 +0000 (Wed, 03 Aug 2011)
Log Message:
-----------
Find all key frames for baked animation export.

Modified Paths:
--------------
    branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp
    branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h

Modified: branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp       
2011-08-03 19:05:58 UTC (rev 39003)
+++ branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp       
2011-08-03 19:12:18 UTC (rev 39004)
@@ -61,6 +61,13 @@
                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 @@
                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 @@
                        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 @@
                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;

Modified: branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h 
2011-08-03 19:05:58 UTC (rev 39003)
+++ branches/soc-2011-pepper/source/blender/collada/AnimationExporter.h 
2011-08-03 19:12:18 UTC (rev 39004)
@@ -96,10 +96,14 @@
 
        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 @@
        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);
        

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

Reply via email to