Blender  V2.59
AnimationImporter.h
Go to the documentation of this file.
00001 /*
00002  * $Id: AnimationImporter.h 35020 2011-02-21 08:38:53Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024  
00029 #ifndef __BC_ANIMATIONIMPORTER_H__
00030 #define __BC_ANIMATIONIMPORTER_H__
00031 
00032 #include <map>
00033 #include <vector>
00034 
00035 #include "COLLADAFWAnimation.h"
00036 #include "COLLADAFWAnimationCurve.h"
00037 #include "COLLADAFWAnimationList.h"
00038 #include "COLLADAFWNode.h"
00039 #include "COLLADAFWUniqueId.h"
00040 
00041 #include "DNA_anim_types.h"
00042 #include "DNA_object_types.h"
00043 #include "DNA_scene_types.h"
00044 
00045 //#include "ArmatureImporter.h"
00046 #include "TransformReader.h"
00047 
00048 #include "collada_internal.h"
00049 
00050 class ArmatureImporter;
00051 
00052 class AnimationImporterBase
00053 {
00054 public:
00055         // virtual void change_eul_to_quat(Object *ob, bAction *act) = 0;
00056 };
00057 
00058 class AnimationImporter : private TransformReader, public AnimationImporterBase
00059 {
00060 private:
00061 
00062         ArmatureImporter *armature_importer;
00063         Scene *scene;
00064 
00065         std::map<COLLADAFW::UniqueId, std::vector<FCurve*> > curve_map;
00066         std::map<COLLADAFW::UniqueId, TransformReader::Animation> uid_animated_map;
00067         // std::map<bActionGroup*, std::vector<FCurve*> > fcurves_actionGroup_map;
00068         std::map<COLLADAFW::UniqueId, const COLLADAFW::AnimationList*> animlist_map;
00069         std::vector<FCurve*> unused_curves;
00070         std::map<COLLADAFW::UniqueId, Object*> joint_objects;
00071         
00072         FCurve *create_fcurve(int array_index, const char *rna_path);
00073         
00074         void create_bezt(FCurve *fcu, float frame, float output);
00075 
00076         // create one or several fcurves depending on the number of parameters being animated
00077         void animation_to_fcurves(COLLADAFW::AnimationCurve *curve);
00078 
00079         void fcurve_deg_to_rad(FCurve *cu);
00080 
00081         void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated);
00082 public:
00083 
00084         AnimationImporter(UnitConverter *conv, ArmatureImporter *arm, Scene *scene);
00085 
00086         ~AnimationImporter();
00087 
00088         bool write_animation(const COLLADAFW::Animation* anim);
00089         
00090         // called on post-process stage after writeVisualScenes
00091         bool write_animation_list(const COLLADAFW::AnimationList* animlist);
00092 
00093         void read_node_transform(COLLADAFW::Node *node, Object *ob);
00094 #if 0
00095         virtual void change_eul_to_quat(Object *ob, bAction *act);
00096 #endif
00097 
00098         // prerequisites:
00099         // animlist_map - map animlist id -> animlist
00100         // curve_map - map anim id -> curve(s)
00101         Object *translate_animation(COLLADAFW::Node *node,
00102                                                                 std::map<COLLADAFW::UniqueId, Object*>& object_map,
00103                                                                 std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
00104                                                                 COLLADAFW::Transformation::TransformationType tm_type,
00105                                                                 Object *par_job = NULL);
00106 
00107         // internal, better make it private
00108         // warning: evaluates only rotation
00109         // prerequisites: animlist_map, curve_map
00110         void evaluate_transform_at_frame(float mat[4][4], COLLADAFW::Node *node, float fra);
00111 
00112         // return true to indicate that mat contains a sane value
00113         bool evaluate_animation(COLLADAFW::Transformation *tm, float mat[4][4], float fra, const char *node_id);
00114 
00115         // gives a world-space mat of joint at rest position
00116         void get_joint_rest_mat(float mat[4][4], COLLADAFW::Node *root, COLLADAFW::Node *node);
00117 
00118         // gives a world-space mat, end's mat not included
00119         bool calc_joint_parent_mat_rest(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end);
00120 
00121 #ifdef ARMATURE_TEST
00122         Object *get_joint_object(COLLADAFW::Node *root, COLLADAFW::Node *node, Object *par_job);
00123 #endif
00124 
00125 #if 0
00126         // recursively evaluates joint tree until end is found, mat then is world-space matrix of end
00127         // mat must be identity on enter, node must be root
00128         bool evaluate_joint_world_transform_at_frame(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end, float fra);
00129 #endif
00130 
00131         void add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurve *fcu);
00132 
00133         void add_bezt(FCurve *fcu, float fra, float value);
00134 };
00135  
00136  #endif