[Bf-blender-cvs] [4f07ecbab90] collada: Refactor Collada: reorganized the BC classes for easier use
Gaia Clary
noreply at git.blender.org
Wed Mar 28 21:31:32 CEST 2018
Commit: 4f07ecbab90f4e866c1c45f50fb01a7edee516ba
Author: Gaia Clary
Date: Wed Mar 28 20:54:45 2018 +0200
Branches: collada
https://developer.blender.org/rB4f07ecbab90f4e866c1c45f50fb01a7edee516ba
Refactor Collada: reorganized the BC classes for easier use
* Made many changes to make the usage of the BCAnimationSampler
much easier.
* Reorganized the header files
* renamed methods for better reading
* Added Matrix typedef to replace float mat[4][4]
* simplifdied the construction of BCSampleData entries
* Added BCCamera BCLamp and BCMaterial classes
* Added support for Camera xfov export
* Added supprot for easier FCurve modifications
through the BCAnimationCurve API
* Added comments
* Removed unnecessary code
* Simplified code wherever possible
===================================================================
M source/blender/collada/AnimationExporter.cpp
M source/blender/collada/AnimationExporter.h
M source/blender/collada/BCAnimationCurve.cpp
M source/blender/collada/BCAnimationCurve.h
M source/blender/collada/BCAnimationCurveContainer.cpp
M source/blender/collada/BCSampleData.cpp
M source/blender/collada/BCSampleData.h
===================================================================
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index f80b3c3b823..8e613ebd024 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -47,8 +47,8 @@ std::map<std::string, std::vector<std::string>> BC_CHANNEL_NAME_FROM_TYPE = {
*/
std::map<BC_animation_transform_type, std::string> BC_ANIMATION_NAME_FROM_TYPE = {
{ BC_ANIMATION_TYPE_ROTATION, "rotation" },
- { BC_ANIMATION_TYPE_ROTATION_EULER, "rotation_euler" },
- { BC_ANIMATION_TYPE_ROTATION_QUAT, "rotation_quaternion" },
+ { BC_ANIMATION_TYPE_ROTATION_EULER, "rotation" },
+ { BC_ANIMATION_TYPE_ROTATION_QUAT, "rotation" },
{ BC_ANIMATION_TYPE_SCALE, "scale" },
{ BC_ANIMATION_TYPE_LOCATION, "location" },
@@ -66,6 +66,7 @@ std::map<BC_animation_transform_type, std::string> BC_ANIMATION_NAME_FROM_TYPE =
{ BC_ANIMATION_TYPE_BLENDER_DIST, "blender/blender_dist" },
/* Cameras */
+ { BC_ANIMATION_TYPE_LENS, "xfov" },
{ BC_ANIMATION_TYPE_XFOV, "xfov" },
{ BC_ANIMATION_TYPE_XMAG, "xmag" },
{ BC_ANIMATION_TYPE_ZFAR, "zfar" },
@@ -76,7 +77,7 @@ std::map<BC_animation_transform_type, std::string> BC_ANIMATION_NAME_FROM_TYPE =
std::string EMPTY_STRING;
-std::string AnimationExporter::get_subchannel(std::string channel, int id)
+std::string AnimationExporter::get_axis_name(std::string channel, int id)
{
std::map<std::string, std::vector<std::string>>::const_iterator it;
it = BC_CHANNEL_NAME_FROM_TYPE.find(channel);
@@ -119,7 +120,7 @@ bool AnimationExporter::exportAnimations(Scene *sce)
{
bool has_anim_data = BCAnimationSampler::has_animations(sce, this->export_settings->export_set);
if (has_anim_data) {
- BCAnimationSampler sampler;
+ animation_sampler = new BCAnimationSampler();
this->scene = sce;
@@ -130,12 +131,11 @@ bool AnimationExporter::exportAnimations(Scene *sce)
for (node = this->export_settings->export_set; node; node = node->next) {
Object *ob = (Object *)node->link;
if (animated_subset.find(ob) != animated_subset.end()) {
- //curve_container.addObject(ob);
- sampler.add_object(ob);
+ animation_sampler->add_object(ob);
}
}
- sampler.sample_scene(scene,
+ animation_sampler->sample_scene(scene,
export_settings->sampling_rate,
/*keyframe_at_end = */ true,
export_settings->open_sim,
@@ -144,13 +144,14 @@ bool AnimationExporter::exportAnimations(Scene *sce)
);
openLibrary();
-
+
std::set<Object *>::iterator it;
for (it = animated_subset.begin(); it != animated_subset.end(); ++it) {
Object *ob = *it;
- exportObjectAnimation(ob, sampler);
+ exportAnimation(ob, *animation_sampler);
}
+ delete animation_sampler;
closeLibrary();
#if 0
@@ -169,7 +170,7 @@ bool AnimationExporter::exportAnimations(Scene *sce)
/* called for each exported object */
-void AnimationExporter::exportObjectAnimation(Object *ob, BCAnimationSampler &sampler)
+void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler)
{
bool container_is_open = false;
@@ -180,34 +181,27 @@ void AnimationExporter::exportObjectAnimation(Object *ob, BCAnimationSampler &sa
* Note: For Armatures the skeletal animation has already been exported (see above)
* However Armatures also can have Object animation.
*/
- if (this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) {
- export_matrix_animation_set(ob, sampler); // actually one matrix curve
- }
- else {
- export_curve_animation_set(ob, sampler); // each curve might have different frames
+ bool export_tm_curves = this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC;
+ if (!export_tm_curves) {
+ export_matrix_animation(ob, sampler); // export all transform_curves as one single matrix animation
}
- if (ob->type == OB_ARMATURE) {
- container_is_open = exportArmatureAnimation(ob, sampler, container_is_open);
- }
+ export_curve_animation_set(ob, sampler, export_tm_curves);
- close_animation_container(container_is_open);
-}
+ if (ob->type == OB_ARMATURE) {
-bool AnimationExporter::exportArmatureAnimation(Object *ob, BCAnimationSampler &sampler, bool has_container)
-{
- /* TODO: This needs to be handled by extra profiles, postponed for now
- * export_morph_animation(ob);
- */
+#ifdef WITH_MORPH_ANIMATION
+ /* TODO: This needs to be handled by extra profiles, postponed for now */
+ export_morph_animation(ob);
+#endif
- if (ob->type == OB_ARMATURE) {
/* Export skeletal animation (if any) */
bArmature *arm = (bArmature *)ob->data;
for (Bone *root_bone = (Bone *)arm->bonebase.first; root_bone; root_bone = root_bone->next)
- export_bone_animation_recursive(ob, root_bone, sampler);
+ export_bone_animations_recursive(ob, root_bone, sampler);
}
- return has_container;
+ close_animation_container(container_is_open);
}
/*
@@ -221,7 +215,7 @@ bool AnimationExporter::exportArmatureAnimation(Object *ob, BCAnimationSampler &
* object hierarchies)
*
*/
-void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSampler &sampler)
+void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_tm_curves)
{
BCFrameSampleMap samples;
BCAnimationCurveMap curves;
@@ -241,6 +235,13 @@ void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSample
continue;
}
+ if (!export_tm_curves && curve.is_transform_curve()) {
+ /* The transform curves will be eported as single matrix animation
+ * So no need to export the curves here again.
+ */
+ continue;
+ }
+
sampler.add_value_set(curve, samples, this->export_settings->export_animation_type); // prepare curve
if (curve.is_flat())
continue;
@@ -249,7 +250,7 @@ void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSample
}
}
-void AnimationExporter::export_matrix_animation_set(Object *ob, BCAnimationSampler &sampler)
+void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &sampler)
{
std::vector<float> frames;
sampler.get_frame_set(frames, ob);
@@ -257,31 +258,22 @@ void AnimationExporter::export_matrix_animation_set(Object *ob, BCAnimationSampl
BCMatrixSampleMap samples;
bool is_flat = sampler.get_samples(samples, ob);
if (!is_flat) {
- export_matrix_animation(ob, frames, samples, sampler); // there is just one curve to export here
- }
- }
-}
-
-void AnimationExporter::export_matrix_animation(
- Object *ob,
- BCFrames &frames,
- BCMatrixSampleMap &samples,
- BCAnimationSampler &sampler)
-{
- bAction *action = bc_getSceneObjectAction(ob);
- std::string name = id_name(ob);
- std::string action_name = (action == nullptr) ? name+"-action" : id_name(action);
- std::string channel_type = "transform";
- std::string axis = "";
- std::string id = bc_get_action_id(action_name, name, channel_type, axis);
+ bAction *action = bc_getSceneObjectAction(ob);
+ std::string name = id_name(ob);
+ std::string action_name = (action == nullptr) ? name + "-action" : id_name(action);
+ std::string channel_type = "transform";
+ std::string axis = "";
+ std::string id = bc_get_action_id(action_name, name, channel_type, axis);
- std::string target = translate_id(name) + '/' + channel_type;
+ std::string target = translate_id(name) + '/' + channel_type;
- export_collada_matrix_animation( id, name, target, frames, samples);
+ export_collada_matrix_animation(id, name, target, frames, samples);
+ }
+ }
}
//write bone animations in transform matrix sources
-void AnimationExporter::export_bone_animation_recursive(Object *ob, Bone *bone, BCAnimationSampler &sampler)
+void AnimationExporter::export_bone_animations_recursive(Object *ob, Bone *bone, BCAnimationSampler &sampler)
{
std::vector<float> frames;
sampler.get_frame_set(frames, ob, bone);
@@ -295,10 +287,13 @@ void AnimationExporter::export_bone_animation_recursive(Object *ob, Bone *bone,
}
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next)
- export_bone_animation_recursive(ob, child, sampler);
+ export_bone_animations_recursive(ob, child, sampler);
}
-
+#ifdef WITH_MORPH_ANIMATION
+/* TODO: This function needs to be implemented similar to the material animation export
+ So we have to update BCSample for this to work.
+*/
void AnimationExporter::export_morph_animation(Object *ob, BCAnimationSampler &sampler)
{
FCurve *fcu;
@@ -318,6 +313,7 @@ void AnimationExporter::export_morph_animation(Object *ob, BCAnimationSampler &s
}
}
+#endif
/* Euler sources from quternion sources
* Important: We assume the object has a scene action.
@@ -336,7 +332,7 @@ void AnimationExporter::get_eul_source_for_quat(std::vector<float> &values, Obje
int curve_count = 0;
while (fcu) {
- std::string transformName = extract_transform_name(fcu->rna_path);
+ std::string transformName = bc_string_after(fcu->rna_path, '.');
if (transformName == "rotation_quaternion" ) {
curve_count += 1;
@@ -360,28 +356,71 @@ void AnimationExporter::get_eul_source_for_quat(std::vector<float> &values, Obje
}
}
-void AnimationExporter::create_keyframed_animation(
- Object *ob,
- FCurve *fcu,
- BC_animation_transform_type tm_type,
- bool is_param,
- BCAnimationSampler &sampler,
- Material *ma)
+/*
+* In some special cases the exported Curve needs to be replaced
+* by a modified curve (for collada purposes)
+* This method checks if a conversion is necessary and if applicable
+* returns a pointer to the modified BCAnimationCurve.
+* IMPORTANT: the modified curve must be deleted by the caller when no longer needed
+* if no conversion is needed this method returns a nullptr;
+*/
+BCAnimationCurve *AnimationExporter::get_modified_export_curve(Object *ob, BCAnimationCurve curve)
{
- BCAnimationCurve curve(BC_ANIMATION_CURVE_TYPE_MATERIAL, fcu);
- export_curve_animation(ob, curve);
+ BC_animation_transform_type tm_type = curve.get_transform_type();
+ BCAnimationCurve *mcurve = nullptr;
+ if (tm_type == BC_ANIMATION_TYPE_LENS) {
+
+ /* Create an xfov curve */
+
+ BCFrameSampleMap sample_map;
+ animation_sampler->get_samples(sample_map, ob);
+ mcurve = new BCAn
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list