[Bf-blender-cvs] [b9162200971] collada: First stable version of new Collada Animation Exporter. This still needs cleanup and fixing (wip)
Gaia Clary
noreply at git.blender.org
Wed Mar 28 21:30:55 CEST 2018
Commit: b91622009714987293d53b45f50a7a2b7d3e6dd4
Author: Gaia Clary
Date: Thu Mar 22 23:20:02 2018 +0100
Branches: collada
https://developer.blender.org/rBb91622009714987293d53b45f50a7a2b7d3e6dd4
First stable version of new Collada Animation Exporter.
This still needs cleanup and fixing (wip)
===================================================================
M source/blender/collada/AnimationExporter.cpp
M source/blender/collada/AnimationExporter.h
M source/blender/collada/ArmatureExporter.cpp
M source/blender/collada/ArmatureExporter.h
M source/blender/collada/BCAnimationCurve.cpp
M source/blender/collada/BCAnimationCurve.h
M source/blender/collada/BCAnimationCurveContainer.cpp
M source/blender/collada/BCAnimationCurveContainer.h
M source/blender/collada/BCMatrix.h
M source/blender/collada/ExportSettings.h
M source/blender/collada/collada_utils.cpp
M source/blender/collada/collada_utils.h
M source/blender/editors/io/io_collada.c
===================================================================
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index 749ff997749..7c1b1b33c6a 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -22,80 +22,36 @@
#include "GeometryExporter.h"
#include "AnimationExporter.h"
+#include "AnimationClipExporter.h"
+#include "BCAnimationCurveContainer.h"
#include "MaterialExporter.h"
+#include "collada_utils.h"
-std::map<BC_animation_transform_type, const char*> BC_ANIMATION_NAME_FROM_TYPE = {
- { BC_ANIMATION_TYPE_ROTATION_EULER, "rotation_euler" },
- { BC_ANIMATION_TYPE_ROTATION_QUAT, "rotation_quaternion" },
- { BC_ANIMATION_TYPE_SCALE, "scale" },
- { BC_ANIMATION_TYPE_LOCATION, "location" },
-
- /* Materials */
- { BC_ANIMATION_TYPE_SPECULAR_HARDNESS, "specular_hardness" },
- { BC_ANIMATION_TYPE_SPECULAR_COLOR, "specular_color" },
- { BC_ANIMATION_TYPE_DIFFUSE_COLOR, "diffuse_color" },
- { BC_ANIMATION_TYPE_ALPHA, "alpha" },
- { BC_ANIMATION_TYPE_IOR, "ior" },
-
- /* Lamps */
- { BC_ANIMATION_TYPE_COLOR, "color" },
- { BC_ANIMATION_TYPE_FALL_OFF_ANGLE, "fall_off_angle" },
- { BC_ANIMATION_TYPE_FALL_OFF_EXPONENT, "fall_off_exponent" },
- { BC_ANIMATION_TYPE_BLENDER_DIST, "blender/blender_dist" },
-
- /* Cameras */
- { BC_ANIMATION_TYPE_XFOV, "xfov" },
- { BC_ANIMATION_TYPE_XMAG, "xmag" },
- { BC_ANIMATION_TYPE_ZFAR, "zfar" },
- { BC_ANIMATION_TYPE_ZNEAR, "znear" },
-
- { BC_ANIMATION_TYPE_UNKNOWN, "" }
-};
-std::map<const char*, BC_animation_transform_type> BC_ANIMATION_TYPE_FROM_NAME = {
- { "rotation_euler", BC_ANIMATION_TYPE_ROTATION_EULER },
- { "rotation_quaternion", BC_ANIMATION_TYPE_ROTATION_QUAT },
- { "scale", BC_ANIMATION_TYPE_SCALE },
- { "location", BC_ANIMATION_TYPE_LOCATION },
-
- /* Materials */
- { "specular_hardness", BC_ANIMATION_TYPE_SPECULAR_HARDNESS },
- { "specular_color", BC_ANIMATION_TYPE_SPECULAR_COLOR },
- { "diffuse_color", BC_ANIMATION_TYPE_DIFFUSE_COLOR },
- { "alpha", BC_ANIMATION_TYPE_ALPHA },
- { "ior", BC_ANIMATION_TYPE_IOR },
-
- /* Lamps */
- { "color", BC_ANIMATION_TYPE_COLOR },
- { "fall_off_angle", BC_ANIMATION_TYPE_FALL_OFF_ANGLE },
- { "fall_off_exponent", BC_ANIMATION_TYPE_FALL_OFF_EXPONENT },
- { "blender/blender_dist", BC_ANIMATION_TYPE_BLENDER_DIST },
- /* Lamp RNA to animation type */
- { "spot_size", BC_ANIMATION_TYPE_FALL_OFF_ANGLE },
- { "spot_blend", BC_ANIMATION_TYPE_FALL_OFF_EXPONENT },
- { "distance", BC_ANIMATION_TYPE_BLENDER_DIST },
-
- /* Cameras */
- { "xfov", BC_ANIMATION_TYPE_XFOV },
- { "xmag", BC_ANIMATION_TYPE_XMAG },
- { "zfar", BC_ANIMATION_TYPE_ZFAR },
- { "znear", BC_ANIMATION_TYPE_ZNEAR },
- /* Camera RNA to animation type */
- { "lens", BC_ANIMATION_TYPE_XFOV },
- { "ortho_scale", BC_ANIMATION_TYPE_XMAG },
- { "clip_end", BC_ANIMATION_TYPE_ZFAR },
- { "clip_start", BC_ANIMATION_TYPE_ZNEAR }
+std::map<std::string, std::vector<std::string>> BC_CHANNEL_NAME_FROM_TYPE = {
+ { "color" , { "R", "G", "B" } },
+ { "specular_color", { "R", "G", "B" } },
+ { "diffuse_color", { "R", "G", "B" } },
+ { "alpha", { "R", "G", "B" } },
+ { "scale", { "X", "Y", "Z" } },
+ { "location", { "X", "Y", "Z" } },
+ { "rotation_euler", { "X", "Y", "Z" } }
};
-template<class Functor>
-void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
+std::string EMPTY_STRING;
+
+std::string AnimationExporter::get_subchannel(std::string channel, int id)
{
- LinkNode *node;
- for (node = export_set; node; node = node->next) {
- Object *ob = (Object *)node->link;
- f(ob);
- }
+ std::map<std::string, std::vector<std::string>>::const_iterator it;
+ it = BC_CHANNEL_NAME_FROM_TYPE.find(channel);
+ if (it == BC_CHANNEL_NAME_FROM_TYPE.end())
+ return "";
+
+ const std::vector<std::string> &subchannel = it->second;
+ if (id >= subchannel.size())
+ return "";
+ return subchannel[id];
}
bool AnimationExporter::open_animation_container(bool has_container, Object *ob)
@@ -107,381 +63,169 @@ bool AnimationExporter::open_animation_container(bool has_container, Object *ob)
}
return true;
}
-void AnimationExporter::close_animation_container(bool has_container)
-{
- if (has_container)
- closeAnimation();
-}
-
-bool AnimationExporter::exportAnimations(Scene *sce)
+void AnimationExporter::openAnimationWithClip(std::string action_id, std::string action_name)
{
- bool has_animations = hasAnimations(sce);
- if (has_animations) {
- this->scene = sce;
-
- openLibrary();
-
- forEachObjectInExportSet(sce, *this, this->export_settings->export_set);
+ std::vector<std::string> anim_meta_entry;
+ anim_meta_entry.push_back(translate_id(action_id));
+ anim_meta_entry.push_back(action_name);
+ anim_meta.push_back(anim_meta_entry);
- closeLibrary();
- }
- return has_animations;
+ openAnimation(translate_id(action_id), action_name);
}
-bool AnimationExporter::is_flat_line(std::vector<std::vector<std::vector<double>>> &values)
+void AnimationExporter::close_animation_container(bool has_container)
{
- if (values.size() < 2)
- return true; // need at least 2 entries to be not flat
-
- std::vector<std::vector<double>> refmat = values[0];
- for (int index = 1; index < values.size(); index++) {
- std::vector<std::vector<double>> mat = values[index];
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- if (!bc_in_range(refmat[i][j], mat[i][j], 0.000001))
- return false;
- }
- }
- }
- return true;
+ if (has_container)
+ closeAnimation();
}
-bool AnimationExporter::is_flat_line(std::vector<float> &values, int channel_count)
-{
- for (int i = 0; i < values.size(); i += channel_count) {
- for (int j = 0; j < channel_count; j++) {
- if (!bc_in_range(values[j], values[i+j], 0.000001))
- return false;
- }
- }
- return true;
-}
-/*
- * This function creates a complete LINEAR Collada <Animation> Entry with all needed
- * <source>, <sampler>, and <channel> entries.
- * This is is used for creating sampled Transformation Animations for either:
- *
- * 1-axis animation:
- * times contains the time points in seconds from within the timeline
- * values contains the data (list of single floats)
- * channel_count = 1
- * axis_name = ['X' | 'Y' | 'Z']
- * is_rot indicates if the animation is a rotation
- *
- * 3-axis animation:
- * times contains the time points in seconds from within the timeline
- * values contains the data (list of floats where each 3 entries are one vector)
- * channel_count = 3
- * axis_name = "" (actually not used)
- * is_rot = false (see xxx below)
- *
- * xxx: I tried to create a 3 axis rotation animation
- * like for translation or scale. But i could not
- * figure out how to setup the channel for this case.
- * So for now rotations are exported as 3 separate 1-axis collada animations
- * See export_sampled_animation() further down.
- */
-void AnimationExporter::create_sampled_animation(int channel_count,
- std::vector<float> &frames,
- std::vector<float> &values,
- std::string ob_name,
- std::string channel_type,
- std::string axis_name,
- bool is_rot)
+bool AnimationExporter::exportAnimations(Scene *sce)
{
- char anim_id[200];
-
- if (is_flat_line(values, channel_count))
- return;
-
- BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(), channel_type.c_str(), axis_name.c_str());
-
- openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
-
- /* create input source */
- std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, frames, false, anim_id, "");
-
- /* create output source */
- std::string output_id;
- if (channel_count == 1)
- output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, &values[0], values.size(), is_rot, anim_id, axis_name.c_str());
- else if (channel_count == 3)
- output_id = create_xyz_source(&values[0], frames.size(), anim_id);
- else if (channel_count == 16)
- output_id = create_4x4_source(frames, values, anim_id);
-
- std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
- COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
- std::string empty;
- sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
- sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
+ bool has_animations = false;
- /* TODO create in/out tangents source (LINEAR) */
- std::string interpolation_id = fake_interpolation_source(frames.size(), anim_id, "");
+ has_animations = hasAnimations(sce);
- /* Create Sampler */
- sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
- addSampler(sampler);
-
- /* Create channel */
- std::string target = translate_id(ob_name) + "/" + channel_type + axis_name + ((is_rot) ? ".ANGLE" : "");
- addChannel(COLLADABU::URI(empty, sampler_id), target);
-
- closeAnimation();
-
-}
-
-/*
- * Export all animation FCurves of an Object.
- *
- * Note: This uses the keyframes as sample points,
- * and exports "baked keyframes" while keeping the tangent infromation
- * of the FCurves intact. This works for simple cases, but breaks
- * especially when negative scales are involved in the animation.
- *
- * If it is necessary to conserve the Animation precisely then
- * use export_sampled_animation_set() instead.
- */
-void AnimationExporter::export_keyframed_animation_set(Object *ob)
-{
- bAction *action = bc_getSceneObjectAction(ob);
- if (!action) {
- return; /* Object has no animation */
- }
+ if (has_animations) {
+ BCAnimationSampler sampler;
- FCurve *fcu = (FCurve *)action->curves.first;
- if (!fcu) {
- return; /* animation has no fcurves */
- }
+ this->scene = sce;
- if (this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) {
+ std::set<Object *> animated_subset;
+ BCAnimationSampler::get_animated_subset(animated_subset, this->export_settings->export_set);
- std::vector<float> frames;
- find_keyframes(action, frames);
- if (frames.size() > 0)
- export_sampled_matrix_animation(ob, frames);
- }
- else {
- char *channel_type;
- while (fcu) {
- //for armature animations as objects
- if (ob->type == OB_ARMATURE)
- channel_type = fcu->rna_path;
- el
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list