Blender V4.5
AnimationExporter.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <cstdlib>
8
9#include "BCAnimationCurve.h"
10
11#include "DNA_action_types.h"
12#include "DNA_armature_types.h"
13#include "DNA_object_types.h"
14
15#include "COLLADASWInputList.h"
16#include "COLLADASWLibraryAnimations.h"
17#include "COLLADASWSource.h"
18
19#include "BCAnimationSampler.h"
20
21#include <vector>
22
28
30
31class AnimationExporter : COLLADASW::LibraryAnimations {
32 private:
33 COLLADASW::StreamWriter *sw;
34 BCExportSettings &export_settings;
35
36 BC_global_rotation_type get_global_rotation_type(Object *ob);
37
38 public:
39 AnimationExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
40 : COLLADASW::LibraryAnimations(sw), sw(sw), export_settings(export_settings)
41 {
42 }
43
44 bool exportAnimations();
45
47 void operator()(Object *ob);
48
49 protected:
51
53
55
56 void write_bone_animation(Object *ob_arm, Bone *bone);
57
58 void sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type);
59
61
62 void sample_animation(float *v,
63 std::vector<float> &frames,
64 int type,
65 Bone *bone,
66 Object *ob_arm,
67 bPoseChannel *pChan);
68
69 void sample_animation(std::vector<float[4][4]> &mats,
70 std::vector<float> &frames,
71 Bone *bone,
72 Object *ob_arm,
73 bPoseChannel *pChan);
74
75 /* dae_bone_animation -> add_bone_animation
76 * (blend this into dae_bone_animation) */
77 void dae_bone_animation(std::vector<float> &fra,
78 float *v,
79 int tm_type,
80 int axis,
81 std::string ob_name,
82 std::string bone_name);
83
84 void dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone);
85
86 void dae_baked_object_animation(std::vector<float> &fra, Object *ob);
87
88 float convert_time(float frame);
89
90 float convert_angle(float angle);
91
92 std::vector<std::vector<std::string>> anim_meta;
93
95 void exportAnimation(Object *ob, BCAnimationSampler &sampler);
96
107 void export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_as_matrix);
108
111
114
116 void export_bone_animations_recursive(Object *ob_arm, Bone *bone, BCAnimationSampler &sampler);
117
119 void export_bone_animation(Object *ob, Bone *bone, BCFrames &frames, BCMatrixSampleMap &samples);
120
122 void export_collada_curve_animation(std::string id,
123 std::string name,
124 std::string target,
125 std::string axis,
126 BCAnimationCurve &curve,
127 BC_global_rotation_type global_rotation_type);
128
130 void export_collada_matrix_animation(std::string id,
131 std::string name,
132 std::string target,
133 BCFrames &frames,
134 BCMatrixSampleMap &samples,
135 BC_global_rotation_type global_rotation_type,
136 Matrix &parentinv);
137
147 BCAnimationCurve &curve,
148 BCAnimationCurveMap &curves);
149
150 /* Helper functions. */
151
152 void openAnimationWithClip(std::string id, std::string name);
153 bool open_animation_container(bool has_container, Object *ob);
154 void close_animation_container(bool has_container);
155
158 COLLADASW::InputSemantic::Semantics semantic,
159 std::vector<float> &values,
160 const std::string &anim_id,
161 const std::string axis_name);
162
165 const std::string &anim_id,
166 BC_global_rotation_type global_rotation_type,
167 Matrix &parentinv);
168
170 std::string collada_linear_interpolation_source(int tot, const std::string &anim_id);
171
172 /* source ID = animation_name + semantic_suffix */
173
174 std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic);
175
176 void add_source_parameters(COLLADASW::SourceBase::ParameterNameList &param,
177 COLLADASW::InputSemantic::Semantics semantic,
178 bool is_rot,
179 const std::string axis,
180 bool transform);
181
183 COLLADASW::InputSemantic::Semantics semantic,
184 bool is_angle,
185 float *values);
187 float sample_frame,
188 COLLADASW::InputSemantic::Semantics semantic,
189 bool is_angle,
190 float *values);
191
192 std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic,
193 BCAnimationCurve &curve,
194 const std::string &anim_id,
195 const std::string axis_name);
196
197 std::string collada_interpolation_source(const BCAnimationCurve &curve,
198 const std::string &anim_id,
199 std::string axis_name,
200 bool *has_tangents);
201
202 std::string get_axis_name(std::string channel, int id);
203 std::string get_collada_name(std::string channel_type) const;
208 std::string get_collada_sid(const BCAnimationCurve &curve, const std::string axis_name);
209
210 /* ===================================== */
211 /* Currently unused or not (yet?) needed */
212 /* ===================================== */
213
214 bool is_bone_deform_group(Bone *bone);
215
216#if 0
217 BC_animation_transform_type _get_transform_type(const std::string path);
218 void get_eul_source_for_quat(std::vector<float> &cache, Object *ob);
219#endif
220
221#ifdef WITH_MORPH_ANIMATION
223#endif
224};
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
float[4][4] Matrix
Object is a sort of wrapper for general info.
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
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)