2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory, Sukhitha Jayathilake.
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file AnimationImporter.h
27 #ifndef __ANIMATIONIMPORTER_H__
28 #define __ANIMATIONIMPORTER_H__
33 #include "COLLADAFWAnimation.h"
34 #include "COLLADAFWAnimationCurve.h"
35 #include "COLLADAFWAnimationList.h"
36 #include "COLLADAFWNode.h"
37 #include "COLLADAFWUniqueId.h"
38 #include "COLLADAFWLight.h"
39 #include "COLLADAFWCamera.h"
40 #include "COLLADAFWMaterial.h"
41 #include "COLLADAFWEffect.h"
42 #include "COLLADAFWInstanceGeometry.h"
45 #include "DNA_anim_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_lamp_types.h"
49 #include "DNA_camera_types.h"
52 //#include "ArmatureImporter.h"
53 #include "TransformReader.h"
55 #include "collada_internal.h"
57 class ArmatureImporter;
59 class AnimationImporterBase
62 // virtual void change_eul_to_quat(Object *ob, bAction *act) = 0;
65 class AnimationImporter : private TransformReader, public AnimationImporterBase
69 ArmatureImporter *armature_importer;
72 std::map<COLLADAFW::UniqueId, std::vector<FCurve*> > curve_map;
73 std::map<COLLADAFW::UniqueId, TransformReader::Animation> uid_animated_map;
74 // std::map<bActionGroup*, std::vector<FCurve*> > fcurves_actionGroup_map;
75 std::map<COLLADAFW::UniqueId, const COLLADAFW::AnimationList*> animlist_map;
76 std::vector<FCurve*> unused_curves;
77 std::map<COLLADAFW::UniqueId, Object*> joint_objects;
79 FCurve *create_fcurve(int array_index, const char *rna_path);
81 void create_bezt(FCurve *fcu, float frame, float output);
83 // create one or several fcurves depending on the number of parameters being animated
84 void animation_to_fcurves(COLLADAFW::AnimationCurve *curve);
86 void fcurve_deg_to_rad(FCurve *cu);
88 void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated);
113 MATERIAL_SHININESS = 2,
114 MATERIAL_SPEC_COLOR = 4,
115 MATERIAL_DIFF_COLOR = 1 << 3,
116 MATERIAL_TRANSPARENCY = 1 << 4,
117 MATERIAL_IOR = 1 << 5
136 AnimationImporter(UnitConverter *conv, ArmatureImporter *arm, Scene *scene);
138 ~AnimationImporter();
140 bool write_animation(const COLLADAFW::Animation* anim);
142 // called on post-process stage after writeVisualScenes
143 bool write_animation_list(const COLLADAFW::AnimationList* animlist);
145 void read_node_transform(COLLADAFW::Node *node, Object *ob);
147 virtual void change_eul_to_quat(Object *ob, bAction *act);
150 void translate_Animations(COLLADAFW::Node * Node,
151 std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
152 std::multimap<COLLADAFW::UniqueId, Object*>& object_map,
153 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map);
155 AnimMix* get_animation_type( const COLLADAFW::Node * node, std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map );
157 void apply_matrix_curves(Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root, COLLADAFW::Node* node,
158 COLLADAFW::Transformation * tm );
160 void add_bone_animation_sampled(Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root, COLLADAFW::Node* node, COLLADAFW::Transformation * tm);
162 void Assign_transform_animations(COLLADAFW::Transformation* transform,
163 const COLLADAFW::AnimationList::AnimationBinding * binding,
164 std::vector<FCurve*>* curves, bool is_joint, char * joint_path);
166 void Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type);
167 void Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type);
169 int setAnimType ( const COLLADAFW::Animatable * prop, int type, int addition);
171 void modify_fcurve(std::vector<FCurve*>* curves, const char* rna_path, int array_index );
172 void unused_fcurve(std::vector<FCurve*>* curves );
174 // animlist_map - map animlist id -> animlist
175 // curve_map - map anim id -> curve(s)
176 Object * translate_animation_OLD(COLLADAFW::Node *node,
177 std::map<COLLADAFW::UniqueId, Object*>& object_map,
178 std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
179 COLLADAFW::Transformation::TransformationType tm_type,
180 Object *par_job = NULL);
182 void find_frames( std::vector<float>* frames, std::vector<FCurve*>* curves );
183 void find_frames_old( std::vector<float>* frames, COLLADAFW::Node * node, COLLADAFW::Transformation::TransformationType tm_type );
184 // internal, better make it private
185 // warning: evaluates only rotation
186 // prerequisites: animlist_map, curve_map
187 void evaluate_transform_at_frame(float mat[4][4], COLLADAFW::Node *node, float fra);
189 // return true to indicate that mat contains a sane value
190 bool evaluate_animation(COLLADAFW::Transformation *tm, float mat[4][4], float fra, const char *node_id);
192 // gives a world-space mat of joint at rest position
193 void get_joint_rest_mat(float mat[4][4], COLLADAFW::Node *root, COLLADAFW::Node *node);
195 // gives a world-space mat, end's mat not included
196 bool calc_joint_parent_mat_rest(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end);
199 Object *get_joint_object(COLLADAFW::Node *root, COLLADAFW::Node *node, Object *par_job);
203 // recursively evaluates joint tree until end is found, mat then is world-space matrix of end
204 // mat must be identity on enter, node must be root
205 bool evaluate_joint_world_transform_at_frame(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end, float fra);
208 void add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurve *fcu);
210 void add_bezt(FCurve *fcu, float fra, float value);
212 void extra_data_importer(std::string elementName);