Blender V2.61 - r43446
|
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, Jan Diederich, Tod Liverseed. 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00023 #include <stdlib.h> 00024 #include <stdio.h> 00025 #include <math.h> 00026 extern "C" 00027 { 00028 #include "DNA_scene_types.h" 00029 #include "DNA_object_types.h" 00030 #include "DNA_anim_types.h" 00031 #include "DNA_action_types.h" 00032 #include "DNA_curve_types.h" 00033 #include "DNA_lamp_types.h" 00034 #include "DNA_camera_types.h" 00035 #include "DNA_armature_types.h" 00036 #include "DNA_material_types.h" 00037 00038 #include "BKE_DerivedMesh.h" 00039 #include "BKE_fcurve.h" 00040 #include "BKE_animsys.h" 00041 #include "BKE_scene.h" 00042 #ifdef NAN_BUILDINFO 00043 extern char build_rev[]; 00044 #endif 00045 } 00046 00047 #include "MEM_guardedalloc.h" 00048 00049 #include "BKE_action.h" // pose functions 00050 #include "BKE_armature.h" 00051 #include "BKE_object.h" 00052 00053 #include "BLI_math.h" 00054 #include "BLI_string.h" 00055 #include "BLI_listbase.h" 00056 00057 #include "RNA_access.h" 00058 00059 #include "COLLADASWSource.h" 00060 #include "COLLADASWInstanceGeometry.h" 00061 #include "COLLADASWInputList.h" 00062 #include "COLLADASWPrimitves.h" 00063 #include "COLLADASWVertices.h" 00064 #include "COLLADASWLibraryAnimations.h" 00065 #include "COLLADASWParamTemplate.h" 00066 #include "COLLADASWParamBase.h" 00067 #include "COLLADASWSampler.h" 00068 #include "COLLADASWConstants.h" 00069 #include "COLLADASWBaseInputElement.h" 00070 00071 #include "EffectExporter.h" 00072 00073 #include "collada_internal.h" 00074 00075 #include <vector> 00076 #include <algorithm> // std::find 00077 00078 class AnimationExporter: COLLADASW::LibraryAnimations 00079 { 00080 private: 00081 Scene *scene; 00082 COLLADASW::StreamWriter *sw; 00083 00084 public: 00085 00086 AnimationExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryAnimations(sw) { this->sw = sw; } 00087 00088 00089 void exportAnimations(Scene *sce); 00090 00091 // called for each exported object 00092 void operator() (Object *ob); 00093 00094 protected: 00095 00096 void dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material *ma = NULL); 00097 00098 void write_bone_animation_matrix(Object *ob_arm, Bone *bone); 00099 00100 void write_bone_animation(Object *ob_arm, Bone *bone); 00101 00102 void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type); 00103 00104 bool is_bone_deform_group(Bone * bone); 00105 00106 void sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone); 00107 00108 void sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pChan); 00109 00110 void sample_animation(std::vector<float[4][4]> &mats, std::vector<float> &frames, Bone *bone, Object *ob_arm, bPoseChannel *pChan); 00111 00112 // dae_bone_animation -> add_bone_animation 00113 // (blend this into dae_bone_animation) 00114 void dae_bone_animation(std::vector<float> &fra, float *v, int tm_type, int axis, std::string ob_name, std::string bone_name); 00115 00116 void dae_baked_animation(std::vector<float> &fra, Object *ob_arm , Bone *bone); 00117 00118 float convert_time(float frame); 00119 00120 float convert_angle(float angle); 00121 00122 std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic); 00123 00124 void add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param, 00125 COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis , bool transform); 00126 00127 void get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length); 00128 00129 float * get_eul_source_for_quat(Object *ob ); 00130 00131 std::string create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name); 00132 00133 std::string create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name); 00134 00135 std::string create_source_from_vector(COLLADASW::InputSemantic::Semantics semantic, std::vector<float> &fra, bool is_rot, const std::string& anim_id, const char *axis_name); 00136 00137 std::string create_xyz_source(float *v, int tot, const std::string& anim_id); 00138 00139 std::string create_4x4_source(std::vector<float> &frames , Object * ob_arm, Bone *bone , const std::string& anim_id); 00140 00141 std::string create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents); 00142 00143 std::string fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name); 00144 // for rotation, axis name is always appended and the value of append_axis is ignored 00145 std::string get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); 00146 std::string get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); 00147 std::string get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis); 00148 void find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name); 00149 void find_frames(Object *ob, std::vector<float> &fra); 00150 00151 void find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode); 00152 00153 // enable fcurves driving a specific bone, disable all the rest 00154 // if bone_name = NULL enable all fcurves 00155 void enable_fcurves(bAction *act, char *bone_name); 00156 00157 bool hasAnimations(Scene *sce); 00158 00159 char* extract_transform_name(char *rna_path); 00160 00161 std::string getObjectBoneName ( Object *ob,const FCurve * fcu); 00162 };