Blender V2.61 - r43446

AnimationImporter.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory , Sukhitha Jayathilake.
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022  
00027 #ifndef __BC_ANIMATIONIMPORTER_H__
00028 #define __BC_ANIMATIONIMPORTER_H__
00029 
00030 #include <map>
00031 #include <vector>
00032 
00033 #include "COLLADAFWAnimation.h"
00034 #include "COLLADAFWAnimationCurve.h"
00035 #include "COLLADAFWAnimationList.h"
00036 #include "COLLADAFWNode.h"
00037 #include "COLLADAFWUniqueId.h"
00038 #include "COLLADAFWLight.h"
00039 #include "COLLADAFWCamera.h"
00040 #include "COLLADAFWMaterial.h"
00041 #include "COLLADAFWEffect.h"
00042 #include "COLLADAFWInstanceGeometry.h"
00043 
00044 #include "DNA_anim_types.h"
00045 #include "DNA_object_types.h"
00046 #include "DNA_scene_types.h"
00047 #include "DNA_lamp_types.h"
00048 #include "DNA_camera_types.h"
00049 
00050 //#include "ArmatureImporter.h"
00051 #include "TransformReader.h"
00052 
00053 #include "collada_internal.h"
00054 
00055 class ArmatureImporter;
00056 
00057 class AnimationImporterBase
00058 {
00059 public:
00060     // virtual void change_eul_to_quat(Object *ob, bAction *act) = 0;
00061 };
00062 
00063 class AnimationImporter : private TransformReader, public AnimationImporterBase
00064 {
00065 private:
00066 
00067     ArmatureImporter *armature_importer;
00068     Scene *scene;
00069 
00070     std::map<COLLADAFW::UniqueId, std::vector<FCurve*> > curve_map;
00071     std::map<COLLADAFW::UniqueId, TransformReader::Animation> uid_animated_map;
00072     // std::map<bActionGroup*, std::vector<FCurve*> > fcurves_actionGroup_map;
00073     std::map<COLLADAFW::UniqueId, const COLLADAFW::AnimationList*> animlist_map;
00074     std::vector<FCurve*> unused_curves;
00075     std::map<COLLADAFW::UniqueId, Object*> joint_objects;
00076     
00077     FCurve *create_fcurve(int array_index, const char *rna_path);
00078     
00079     void create_bezt(FCurve *fcu, float frame, float output);
00080 
00081     // create one or several fcurves depending on the number of parameters being animated
00082     void animation_to_fcurves(COLLADAFW::AnimationCurve *curve);
00083 
00084     void fcurve_deg_to_rad(FCurve *cu);
00085 
00086     void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated);
00087     
00088     int typeFlag;
00089 
00090     enum lightAnim
00091     {
00092 //      INANIMATE = 0,
00093         LIGHT_COLOR = 2,
00094         LIGHT_FOA = 4,
00095         LIGHT_FOE = 8
00096     };
00097 
00098     enum cameraAnim
00099     {
00100 //      INANIMATE = 0,
00101         CAMERA_XFOV = 2,
00102         CAMERA_XMAG = 4,
00103         CAMERA_ZFAR = 8,
00104         CAMERA_ZNEAR = 16
00105     };
00106 
00107     enum matAnim
00108     {
00109         MATERIAL_SHININESS = 2,
00110         MATERIAL_SPEC_COLOR = 4,
00111         MATERIAL_DIFF_COLOR = 1 << 3,
00112         MATERIAL_TRANSPARENCY = 1 << 4,
00113         MATERIAL_IOR = 1 << 5
00114     };
00115     
00116     enum AnimationType
00117         {
00118             INANIMATE = 0,
00119             NODE_TRANSFORM = 1,
00120         };
00121 
00122     struct AnimMix
00123     {
00124         int transform;
00125         int light;
00126         int camera;
00127         int material;
00128         int texture;
00129     };
00130 public:
00131 
00132     AnimationImporter(UnitConverter *conv, ArmatureImporter *arm, Scene *scene);
00133 
00134     ~AnimationImporter();
00135 
00136     bool write_animation(const COLLADAFW::Animation* anim);
00137     
00138     // called on post-process stage after writeVisualScenes
00139     bool write_animation_list(const COLLADAFW::AnimationList* animlist);
00140 
00141     void read_node_transform(COLLADAFW::Node *node, Object *ob);
00142 #if 0
00143     virtual void change_eul_to_quat(Object *ob, bAction *act);
00144 #endif
00145 
00146     void translate_Animations( COLLADAFW::Node * Node , 
00147                                                    std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
00148                                                    std::map<COLLADAFW::UniqueId, Object*>& object_map ,
00149                                                    std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map);
00150 
00151     AnimMix* get_animation_type( const COLLADAFW::Node * node , std::map<COLLADAFW::UniqueId,const COLLADAFW::Object*> FW_object_map ) ;
00152 
00153     void apply_matrix_curves( Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root ,COLLADAFW::Node* node,
00154                                     COLLADAFW::Transformation * tm );
00155 
00156     void Assign_transform_animations(COLLADAFW::Transformation* transform , 
00157                                      const COLLADAFW::AnimationList::AnimationBinding * binding,
00158                                      std::vector<FCurve*>* curves, bool is_joint, char * joint_path);
00159 
00160     void Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type);
00161     void Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type);
00162 
00163     int setAnimType ( const COLLADAFW::Animatable * prop , int type, int addition);
00164     
00165     void modify_fcurve(std::vector<FCurve*>* curves , const char* rna_path , int array_index );
00166     // prerequisites:
00167     // animlist_map - map animlist id -> animlist
00168     // curve_map - map anim id -> curve(s)
00169     Object * translate_animation_OLD(COLLADAFW::Node *node,
00170                                 std::map<COLLADAFW::UniqueId, Object*>& object_map,
00171                                 std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
00172                                 COLLADAFW::Transformation::TransformationType tm_type,
00173                                 Object *par_job = NULL);
00174     
00175     void find_frames( std::vector<float>* frames , std::vector<FCurve*>* curves );
00176     void find_frames_old( std::vector<float>* frames, COLLADAFW::Node * node, COLLADAFW::Transformation::TransformationType tm_type );
00177     // internal, better make it private
00178     // warning: evaluates only rotation
00179     // prerequisites: animlist_map, curve_map
00180     void evaluate_transform_at_frame(float mat[4][4], COLLADAFW::Node *node, float fra);
00181 
00182     // return true to indicate that mat contains a sane value
00183     bool evaluate_animation(COLLADAFW::Transformation *tm, float mat[4][4], float fra, const char *node_id);
00184 
00185     // gives a world-space mat of joint at rest position
00186     void get_joint_rest_mat(float mat[4][4], COLLADAFW::Node *root, COLLADAFW::Node *node);
00187 
00188     // gives a world-space mat, end's mat not included
00189     bool calc_joint_parent_mat_rest(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end);
00190 
00191 #ifdef ARMATURE_TEST
00192     Object *get_joint_object(COLLADAFW::Node *root, COLLADAFW::Node *node, Object *par_job);
00193 #endif
00194 
00195 #if 0
00196     // recursively evaluates joint tree until end is found, mat then is world-space matrix of end
00197     // mat must be identity on enter, node must be root
00198     bool evaluate_joint_world_transform_at_frame(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end, float fra);
00199 #endif
00200 
00201     void add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurve *fcu);
00202 
00203     void add_bezt(FCurve *fcu, float fra, float value);
00204 
00205     void extra_data_importer(std::string elementName);
00206 };
00207 
00208 #endif