Blender  V2.93
AnimationExporter.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
19 #include <math.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 
23 #include "BCAnimationCurve.h"
24 
25 #include "DNA_action_types.h"
26 #include "DNA_anim_types.h"
27 #include "DNA_armature_types.h"
28 #include "DNA_camera_types.h"
29 #include "DNA_constraint_types.h"
30 #include "DNA_curve_types.h"
31 #include "DNA_light_types.h"
32 #include "DNA_material_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_scene_types.h"
35 
36 #include "BLI_listbase.h"
37 #include "BLI_math.h"
38 #include "BLI_string.h"
39 #include "BLI_utildefines.h"
40 
41 #include "BIK_api.h"
42 #include "BKE_action.h" /* pose functions */
43 #include "BKE_armature.h"
44 #include "BKE_constraint.h"
45 #include "BKE_fcurve.h"
46 #include "BKE_object.h"
47 #include "BKE_scene.h"
48 #include "ED_object.h"
49 
50 #include "MEM_guardedalloc.h"
51 
52 #include "RNA_access.h"
53 
54 #include "COLLADASWBaseInputElement.h"
55 #include "COLLADASWConstants.h"
56 #include "COLLADASWInputList.h"
57 #include "COLLADASWInstanceGeometry.h"
58 #include "COLLADASWLibraryAnimations.h"
59 #include "COLLADASWParamBase.h"
60 #include "COLLADASWParamTemplate.h"
61 #include "COLLADASWPrimitves.h"
62 #include "COLLADASWSampler.h"
63 #include "COLLADASWSource.h"
64 #include "COLLADASWVertices.h"
65 
66 #include "BCAnimationSampler.h"
67 #include "EffectExporter.h"
68 #include "collada_internal.h"
69 
70 #include "IK_solver.h"
71 
72 #include <algorithm> /* std::find */
73 #include <map>
74 #include <vector>
75 
81 
87 
88 class AnimationExporter : COLLADASW::LibraryAnimations {
89  private:
90  COLLADASW::StreamWriter *sw;
91  BCExportSettings &export_settings;
92 
93  BC_global_rotation_type get_global_rotation_type(Object *ob);
94 
95  public:
96  AnimationExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
97  : COLLADASW::LibraryAnimations(sw), sw(sw), export_settings(export_settings)
98  {
99  }
100 
101  bool exportAnimations();
102 
103  /* called for each exported object */
104  void operator()(Object *ob);
105 
106  protected:
108 
110 
112 
113  void write_bone_animation(Object *ob_arm, Bone *bone);
114 
115  void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type);
116 
118 
119  void sample_animation(float *v,
120  std::vector<float> &frames,
121  int type,
122  Bone *bone,
123  Object *ob_arm,
124  bPoseChannel *pChan);
125 
126  void sample_animation(std::vector<float[4][4]> &mats,
127  std::vector<float> &frames,
128  Bone *bone,
129  Object *ob_arm,
130  bPoseChannel *pChan);
131 
132  /* dae_bone_animation -> add_bone_animation
133  * (blend this into dae_bone_animation) */
134  void dae_bone_animation(std::vector<float> &fra,
135  float *v,
136  int tm_type,
137  int axis,
138  std::string ob_name,
139  std::string bone_name);
140 
141  void dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone);
142 
143  void dae_baked_object_animation(std::vector<float> &fra, Object *ob);
144 
145  float convert_time(float frame);
146 
147  float convert_angle(float angle);
148 
149  std::vector<std::vector<std::string>> anim_meta;
150 
151  /* Main entry point into Animation export (called for each exported object) */
152  void exportAnimation(Object *ob, BCAnimationSampler &sampler);
153 
154  /* export animation as separate trans/rot/scale curves */
155  void export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_as_matrix);
156 
157  /* export one single curve */
159 
160  /* export animation as matrix data */
162 
163  /* step through the bone hierarchy */
164  void export_bone_animations_recursive(Object *ob_arm, Bone *bone, BCAnimationSampler &sampler);
165 
166  /* Export for one bone */
167  void export_bone_animation(Object *ob, Bone *bone, BCFrames &frames, BCMatrixSampleMap &samples);
168 
169  /* call to the low level collada exporter */
170  void export_collada_curve_animation(std::string id,
171  std::string name,
172  std::string target,
173  std::string axis,
175  BC_global_rotation_type global_rotation_type);
176 
177  /* call to the low level collada exporter */
178  void export_collada_matrix_animation(std::string id,
179  std::string name,
180  std::string target,
181  BCFrames &frames,
182  BCMatrixSampleMap &samples,
183  BC_global_rotation_type global_rotation_type,
184  Matrix &parentinv);
185 
188  BCAnimationCurveMap &curves);
189 
190  /* Helper functions */
191  void openAnimationWithClip(std::string id, std::string name);
192  bool open_animation_container(bool has_container, Object *ob);
193  void close_animation_container(bool has_container);
194 
195  /* Input and Output sources (single valued) */
197  COLLADASW::InputSemantic::Semantics semantic,
198  std::vector<float> &values,
199  const std::string &anim_id,
200  const std::string axis_name);
201 
202  /* Output sources (matrix data) */
203  std::string collada_source_from_values(BCMatrixSampleMap &samples,
204  const std::string &anim_id,
205  BC_global_rotation_type global_rotation_type,
206  Matrix &parentinv);
207 
208  /* Interpolation sources */
209  std::string collada_linear_interpolation_source(int tot, const std::string &anim_id);
210 
211  /* source ID = animation_name + semantic_suffix */
212 
213  std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic);
214 
215  void add_source_parameters(COLLADASW::SourceBase::ParameterNameList &param,
216  COLLADASW::InputSemantic::Semantics semantic,
217  bool is_rot,
218  const std::string axis,
219  bool transform);
220 
222  COLLADASW::InputSemantic::Semantics semantic,
223  bool is_angle,
224  float *values);
226  float sample_frame,
227  COLLADASW::InputSemantic::Semantics semantic,
228  bool is_angle,
229  float *values);
230 
231  std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic,
233  const std::string &anim_id,
234  const std::string axis_name);
235 
237  const std::string &anim_id,
238  std::string axis_name,
239  bool *has_tangents);
240 
241  std::string get_axis_name(std::string channel, int id);
242  std::string get_collada_name(std::string channel_type) const;
243  std::string get_collada_sid(const BCAnimationCurve &curve, const std::string axis_name);
244 
245  /* ===================================== */
246  /* Currently unused or not (yet?) needed */
247  /* ===================================== */
248 
249  bool is_bone_deform_group(Bone *bone);
250 
251 #if 0
252  BC_animation_transform_type _get_transform_type(const std::string path);
253  void get_eul_source_for_quat(std::vector<float> &cache, Object *ob);
254 #endif
255 
256 #ifdef WITH_MORPH_ANIMATION
258 #endif
259 };
BC_animation_source_type
@ BC_SOURCE_TYPE_TIMEFRAME
@ BC_SOURCE_TYPE_VALUE
@ BC_SOURCE_TYPE_ANGLE
BC_global_rotation_type
@ BC_DATA_ROTATION
@ BC_OBJECT_ROTATION
@ BC_NO_ROTATION
std::map< BCCurveKey, BCAnimationCurve * > BCAnimationCurveMap
std::vector< float > BCFrames
std::map< int, const BCMatrix * > BCMatrixSampleMap
Definition: BCSampleData.h:63
Blender kernel action and pose functionality.
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
void export_collada_matrix_animation(std::string id, std::string name, std::string target, BCFrames &frames, BCMatrixSampleMap &samples, BC_global_rotation_type global_rotation_type, Matrix &parentinv)
std::string get_axis_name(std::string channel, int id)
std::string collada_interpolation_source(const BCAnimationCurve &curve, const std::string &anim_id, std::string axis_name, bool *has_tangents)
void add_source_parameters(COLLADASW::SourceBase::ParameterNameList &param, COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const std::string axis, bool transform)
void close_animation_container(bool has_container)
void openAnimationWithClip(std::string id, std::string name)
void export_object_constraint_animation(Object *ob)
void write_bone_animation(Object *ob_arm, Bone *bone)
void sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
bool open_animation_container(bool has_container, Object *ob)
void export_collada_curve_animation(std::string id, std::string name, std::string target, std::string axis, BCAnimationCurve &curve, BC_global_rotation_type global_rotation_type)
void exportAnimation(Object *ob, BCAnimationSampler &sampler)
float convert_angle(float angle)
void operator()(Object *ob)
void write_bone_animation_matrix(Object *ob_arm, Bone *bone)
void export_matrix_animation(Object *ob, BCAnimationSampler &sampler)
void export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_as_matrix)
void dae_baked_object_animation(std::vector< float > &fra, Object *ob)
void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type)
bool is_bone_deform_group(Bone *bone)
void export_bone_animations_recursive(Object *ob_arm, Bone *bone, BCAnimationSampler &sampler)
AnimationExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void export_bone_animation(Object *ob, Bone *bone, BCFrames &frames, BCMatrixSampleMap &samples)
BCAnimationCurve * get_modified_export_curve(Object *ob, BCAnimationCurve &curve, BCAnimationCurveMap &curves)
void export_curve_animation(Object *ob, BCAnimationCurve &curve)
void export_morph_animation(Object *ob)
std::string get_collada_name(std::string channel_type) const
std::string collada_linear_interpolation_source(int tot, const std::string &anim_id)
std::string get_collada_sid(const BCAnimationCurve &curve, const std::string axis_name)
void sample_animation(float *v, std::vector< float > &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pChan)
std::vector< std::vector< std::string > > anim_meta
void sample_animation(std::vector< float[4][4]> &mats, std::vector< float > &frames, Bone *bone, Object *ob_arm, bPoseChannel *pChan)
std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic)
int get_point_in_curve(const BCAnimationCurve &curve, float sample_frame, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values)
std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic, BCAnimationCurve &curve, const std::string &anim_id, const std::string axis_name)
int get_point_in_curve(BCBezTriple &bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values)
std::string collada_source_from_values(BC_animation_source_type source_type, COLLADASW::InputSemantic::Semantics semantic, std::vector< float > &values, const std::string &anim_id, const std::string axis_name)
void dae_baked_animation(std::vector< float > &fra, Object *ob_arm, Bone *bone)
float convert_time(float frame)
void dae_bone_animation(std::vector< float > &fra, float *v, int tm_type, int axis, std::string ob_name, std::string bone_name)
Curve curve
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
Definition: vector.h:39