Blender  V3.3
AnimationExporter.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
5 #include <math.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "BCAnimationCurve.h"
10 
11 #include "DNA_action_types.h"
12 #include "DNA_anim_types.h"
13 #include "DNA_armature_types.h"
14 #include "DNA_camera_types.h"
15 #include "DNA_constraint_types.h"
16 #include "DNA_curve_types.h"
17 #include "DNA_light_types.h"
18 #include "DNA_material_types.h"
19 #include "DNA_object_types.h"
20 #include "DNA_scene_types.h"
21 
22 #include "BLI_listbase.h"
23 #include "BLI_math.h"
24 #include "BLI_string.h"
25 #include "BLI_utildefines.h"
26 
27 #include "BIK_api.h"
28 #include "BKE_action.h" /* pose functions */
29 #include "BKE_armature.h"
30 #include "BKE_constraint.h"
31 #include "BKE_fcurve.h"
32 #include "BKE_object.h"
33 #include "BKE_scene.h"
34 #include "ED_object.h"
35 
36 #include "MEM_guardedalloc.h"
37 
38 #include "RNA_access.h"
39 
40 #include "COLLADASWBaseInputElement.h"
41 #include "COLLADASWConstants.h"
42 #include "COLLADASWInputList.h"
43 #include "COLLADASWInstanceGeometry.h"
44 #include "COLLADASWLibraryAnimations.h"
45 #include "COLLADASWParamBase.h"
46 #include "COLLADASWParamTemplate.h"
47 #include "COLLADASWPrimitves.h"
48 #include "COLLADASWSampler.h"
49 #include "COLLADASWSource.h"
50 #include "COLLADASWVertices.h"
51 
52 #include "BCAnimationSampler.h"
53 #include "EffectExporter.h"
54 #include "collada_internal.h"
55 
56 #include "IK_solver.h"
57 
58 #include <algorithm> /* std::find */
59 #include <map>
60 #include <vector>
61 
67 
73 
74 class AnimationExporter : COLLADASW::LibraryAnimations {
75  private:
76  COLLADASW::StreamWriter *sw;
77  BCExportSettings &export_settings;
78 
79  BC_global_rotation_type get_global_rotation_type(Object *ob);
80 
81  public:
82  AnimationExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
83  : COLLADASW::LibraryAnimations(sw), sw(sw), export_settings(export_settings)
84  {
85  }
86 
87  bool exportAnimations();
88 
90  void operator()(Object *ob);
91 
92  protected:
94 
96 
97  void write_bone_animation_matrix(Object *ob_arm, Bone *bone);
98 
99  void write_bone_animation(Object *ob_arm, Bone *bone);
100 
101  void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type);
102 
104 
105  void sample_animation(float *v,
106  std::vector<float> &frames,
107  int type,
108  Bone *bone,
109  Object *ob_arm,
110  bPoseChannel *pChan);
111 
112  void sample_animation(std::vector<float[4][4]> &mats,
113  std::vector<float> &frames,
114  Bone *bone,
115  Object *ob_arm,
116  bPoseChannel *pChan);
117 
118  /* dae_bone_animation -> add_bone_animation
119  * (blend this into dae_bone_animation) */
120  void dae_bone_animation(std::vector<float> &fra,
121  float *v,
122  int tm_type,
123  int axis,
124  std::string ob_name,
125  std::string bone_name);
126 
127  void dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone);
128 
129  void dae_baked_object_animation(std::vector<float> &fra, Object *ob);
130 
131  float convert_time(float frame);
132 
133  float convert_angle(float angle);
134 
135  std::vector<std::vector<std::string>> anim_meta;
136 
139 
150  void export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_as_matrix);
151 
154 
157 
160 
162  void export_bone_animation(Object *ob, Bone *bone, BCFrames &frames, BCMatrixSampleMap &samples);
163 
165  void export_collada_curve_animation(std::string id,
166  std::string name,
167  std::string target,
168  std::string axis,
170  BC_global_rotation_type global_rotation_type);
171 
173  void export_collada_matrix_animation(std::string id,
174  std::string name,
175  std::string target,
176  BCFrames &frames,
177  BCMatrixSampleMap &samples,
178  BC_global_rotation_type global_rotation_type,
179  Matrix &parentinv);
180 
192 
193  /* Helper functions. */
194 
195  void openAnimationWithClip(std::string id, std::string name);
196  bool open_animation_container(bool has_container, Object *ob);
197  void close_animation_container(bool has_container);
198 
201  COLLADASW::InputSemantic::Semantics semantic,
202  std::vector<float> &values,
203  const std::string &anim_id,
204  const std::string axis_name);
205 
207  std::string collada_source_from_values(BCMatrixSampleMap &samples,
208  const std::string &anim_id,
209  BC_global_rotation_type global_rotation_type,
210  Matrix &parentinv);
211 
213  std::string collada_linear_interpolation_source(int tot, const std::string &anim_id);
214 
215  /* source ID = animation_name + semantic_suffix */
216 
217  std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic);
218 
219  void add_source_parameters(COLLADASW::SourceBase::ParameterNameList &param,
220  COLLADASW::InputSemantic::Semantics semantic,
221  bool is_rot,
222  const std::string axis,
223  bool transform);
224 
226  COLLADASW::InputSemantic::Semantics semantic,
227  bool is_angle,
228  float *values);
230  float sample_frame,
231  COLLADASW::InputSemantic::Semantics semantic,
232  bool is_angle,
233  float *values);
234 
235  std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic,
237  const std::string &anim_id,
238  const std::string axis_name);
239 
241  const std::string &anim_id,
242  std::string axis_name,
243  bool *has_tangents);
244 
245  std::string get_axis_name(std::string channel, int id);
246  std::string get_collada_name(std::string channel_type) const;
251  std::string get_collada_sid(const BCAnimationCurve &curve, const std::string axis_name);
252 
253  /* ===================================== */
254  /* Currently unused or not (yet?) needed */
255  /* ===================================== */
256 
257  bool is_bone_deform_group(Bone *bone);
258 
259 #if 0
260  BC_animation_transform_type _get_transform_type(const std::string path);
261  void get_eul_source_for_quat(std::vector<float> &cache, Object *ob);
262 #endif
263 
264 #ifdef WITH_MORPH_ANIMATION
266 #endif
267 };
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:48
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.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
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
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
ccl_gpu_kernel_postfix ccl_global float int int int sw