[Bf-blender-cvs] [b7bd8d813fd] master: feature collada: Allow export/import of skeletal animations as curves

Gaia Clary noreply at git.blender.org
Sun Jun 2 23:02:02 CEST 2019


Commit: b7bd8d813fd92d25eceedc7b1f23894c12bba6f9
Author: Gaia Clary
Date:   Sun Jun 2 19:06:14 2019 +0200
Branches: master
https://developer.blender.org/rBb7bd8d813fd92d25eceedc7b1f23894c12bba6f9

feature collada: Allow export/import of skeletal animations as curves

===================================================================

M	source/blender/collada/AnimationExporter.cpp
M	source/blender/collada/AnimationImporter.cpp
M	source/blender/collada/AnimationImporter.h
M	source/blender/collada/ArmatureImporter.cpp
M	source/blender/collada/ArmatureImporter.h
M	source/blender/collada/BCAnimationCurve.cpp
M	source/blender/collada/BCAnimationCurve.h
M	source/blender/collada/BCSampleData.cpp
M	source/blender/collada/TransformWriter.cpp

===================================================================

diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index c30c0d4ea08..a2c629bd0f1 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -27,8 +27,9 @@
 
 std::string EMPTY_STRING;
 
-std::string AnimationExporter::get_axis_name(std::string channel, int id)
+std::string AnimationExporter::get_axis_name(std::string channel_type, int id)
 {
+
   static std::map<std::string, std::vector<std::string>> BC_COLLADA_AXIS_FROM_TYPE = {
       {"color", {"R", "G", "B"}},
       {"specular_color", {"R", "G", "B"}},
@@ -39,7 +40,8 @@ std::string AnimationExporter::get_axis_name(std::string channel, int id)
       {"rotation_euler", {"X", "Y", "Z"}}};
 
   std::map<std::string, std::vector<std::string>>::const_iterator it;
-  it = BC_COLLADA_AXIS_FROM_TYPE.find(channel);
+
+  it = BC_COLLADA_AXIS_FROM_TYPE.find(channel_type);
   if (it == BC_COLLADA_AXIS_FROM_TYPE.end()) {
     return "";
   }
@@ -146,7 +148,7 @@ void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler)
 
   export_curve_animation_set(ob, sampler, export_as_matrix);
 
-  if (ob->type == OB_ARMATURE) {
+  if (ob->type == OB_ARMATURE && export_as_matrix) {
 
 #ifdef WITH_MORPH_ANIMATION
     /* TODO: This needs to be handled by extra profiles, postponed for now */
@@ -183,7 +185,8 @@ void AnimationExporter::export_curve_animation_set(Object *ob,
   BCAnimationCurveMap::iterator it;
   for (it = curves->begin(); it != curves->end(); ++it) {
     BCAnimationCurve &curve = *it->second;
-    if (curve.get_channel_target() == "rotation_quaternion") {
+    std::string channel_type = curve.get_channel_type();
+    if (channel_type == "rotation_quaternion") {
       /* Can not export Quaternion animation in Collada as far as i know)
        * Maybe automatically convert to euler rotation?
        * Discard for now. */
@@ -286,9 +289,9 @@ BCAnimationCurve *AnimationExporter::get_modified_export_curve(Object *ob,
                                                                BCAnimationCurve &curve,
                                                                BCAnimationCurveMap &curves)
 {
-  std::string channel_target = curve.get_channel_target();
+  std::string channel_type = curve.get_channel_type();
   BCAnimationCurve *mcurve = NULL;
-  if (channel_target == "lens") {
+  if (channel_type == "lens") {
 
     /* Create an xfov curve */
 
@@ -339,7 +342,8 @@ void AnimationExporter::export_curve_animation(Object *ob, BCAnimationCurve &cur
 
   int channel_index = curve.get_channel_index();
   /* RGB or XYZ or "" */
-  std::string axis = get_axis_name(channel_target, channel_index);
+  std::string channel_type = curve.get_channel_type();
+  std::string axis = get_axis_name(channel_type, channel_index);
 
   std::string action_name;
   bAction *action = bc_getSceneObjectAction(ob);
@@ -767,7 +771,7 @@ std::string AnimationExporter::collada_linear_interpolation_source(int tot,
   return source_id;
 }
 
-const std::string AnimationExporter::get_collada_name(std::string channel_target) const
+const std::string AnimationExporter::get_collada_name(std::string channel_type) const
 {
   /*
    * Translation table to map FCurve animation types to Collada animation.
@@ -811,11 +815,10 @@ const std::string AnimationExporter::get_collada_name(std::string channel_target
       {"clip_start", "znear"}};
 
   std::map<std::string, std::string>::iterator name_it = BC_CHANNEL_BLENDER_TO_COLLADA.find(
-      channel_target);
+      channel_type);
   if (name_it == BC_CHANNEL_BLENDER_TO_COLLADA.end()) {
     return "";
   }
-
   std::string tm_name = name_it->second;
   return tm_name;
 }
@@ -828,7 +831,8 @@ std::string AnimationExporter::get_collada_sid(const BCAnimationCurve &curve,
                                                const std::string axis_name)
 {
   std::string channel_target = curve.get_channel_target();
-  std::string tm_name = get_collada_name(channel_target);
+  std::string channel_type = curve.get_channel_type();
+  std::string tm_name = get_collada_name(channel_type);
 
   bool is_angle = curve.is_rotation_curve();
 
diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp
index 4c96ebf2603..ef6c81efff7 100644
--- a/source/blender/collada/AnimationImporter.cpp
+++ b/source/blender/collada/AnimationImporter.cpp
@@ -170,6 +170,16 @@ void AnimationImporter::fcurve_deg_to_rad(FCurve *cu)
   }
 }
 
+void AnimationImporter::fcurve_scale(FCurve *cu, int scale)
+{
+  for (unsigned int i = 0; i < cu->totvert; i++) {
+    /* TODO convert handles too */
+    cu->bezt[i].vec[1][1] *= scale;
+    cu->bezt[i].vec[0][1] *= scale;
+    cu->bezt[i].vec[2][1] *= scale;
+  }
+}
+
 void AnimationImporter::fcurve_is_used(FCurve *fcu)
 {
   unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu),
@@ -451,7 +461,8 @@ virtual void AnimationImporter::change_eul_to_quat(Object *ob, bAction *act)
 /* sets the rna_path and array index to curve */
 void AnimationImporter::modify_fcurve(std::vector<FCurve *> *curves,
                                       const char *rna_path,
-                                      int array_index)
+                                      int array_index,
+                                      int scale)
 {
   std::vector<FCurve *>::iterator it;
   int i;
@@ -466,6 +477,10 @@ void AnimationImporter::modify_fcurve(std::vector<FCurve *> *curves,
       fcu->array_index = array_index;
     }
 
+    if (scale != 1) {
+      fcurve_scale(fcu, scale);
+    }
+
     fcurve_is_used(fcu);
   }
 }
@@ -581,10 +596,20 @@ void AnimationImporter::Assign_transform_animations(
             modify_fcurve(curves, rna_path, 0);
           }
           else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
-            modify_fcurve(curves, rna_path, 1);
+            if (is_joint) {
+              modify_fcurve(curves, rna_path, 2, -1);  // Bone animation from dae to blender
+            }
+            else {
+              modify_fcurve(curves, rna_path, 1);
+            }
           }
           else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
-            modify_fcurve(curves, rna_path, 2);
+            if (is_joint) {
+              modify_fcurve(curves, rna_path, 1);  // Bone animation from dae to blender
+            }
+            else {
+              modify_fcurve(curves, rna_path, 2);
+            }
           }
           else {
             unused_fcurve(curves);
@@ -1061,28 +1086,23 @@ void AnimationImporter::translate_Animations(
             apply_matrix_curves(ob, animcurves, root, node, transform);
           }
           else {
-            if (is_joint) {
-              add_bone_animation_sampled(ob, animcurves, root, node, transform);
-            }
-            else {
-              /* calculate rnapaths and array index of fcurves according to transformation and
-               * animation class */
-              Assign_transform_animations(
-                  transform, &bindings[j], &animcurves, is_joint, joint_path);
-
-              std::vector<FCurve *>::iterator iter;
-              /* Add the curves of the current animation to the object */
-              for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
-                FCurve *fcu = *iter;
-
-                BLI_addtail(AnimCurves, fcu);
-                fcurve_is_used(fcu);
-              }
+            /* calculate rnapaths and array index of fcurves according to transformation and
+             * animation class */
+            Assign_transform_animations(
+                transform, &bindings[j], &animcurves, is_joint, joint_path);
+
+            std::vector<FCurve *>::iterator iter;
+            /* Add the curves of the current animation to the object */
+            for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
+              FCurve *fcu = *iter;
+
+              BLI_addtail(AnimCurves, fcu);
+              fcurve_is_used(fcu);
             }
           }
         }
       }
-      if (is_rotation && !is_joint) {
+      if (is_rotation && !(is_joint || is_matrix)) {
         ob->rotmode = ROT_MODE_EUL;
       }
     }
@@ -1822,10 +1842,10 @@ Object *AnimationImporter::translate_animation_OLD(
   if (is_rotation || is_matrix) {
     if (is_joint) {
       bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name);
-      chan->rotmode = ROT_MODE_QUAT;
+      chan->rotmode = (is_matrix)? ROT_MODE_QUAT : ROT_MODE_EUL;
     }
     else {
-      ob->rotmode = ROT_MODE_QUAT;
+      ob->rotmode = (is_matrix) ? ROT_MODE_QUAT : ROT_MODE_EUL;
     }
   }
 
diff --git a/source/blender/collada/AnimationImporter.h b/source/blender/collada/AnimationImporter.h
index f15c02183c7..c62ffdbafd3 100644
--- a/source/blender/collada/AnimationImporter.h
+++ b/source/blender/collada/AnimationImporter.h
@@ -80,6 +80,7 @@ class AnimationImporter : private TransformReader, public AnimationImporterBase
   void animation_to_fcurves(COLLADAFW::AnimationCurve *curve);
 
   void fcurve_deg_to_rad(FCurve *cu);
+  void fcurve_scale(FCurve *cu, int scale);
 
   void fcurve_is_used(FCurve *fcu);
 
@@ -194,7 +195,7 @@ class AnimationImporter : private TransformReader, public AnimationImporterBase
 
   int setAnimType(const COLLADAFW::Animatable *prop, int type, int addition);
 
-  void modify_fcurve(std::vector<FCurve *> *curves, const char *rna_path, int array_index);
+  void modify_fcurve(std::vector<FCurve *> *curves, const char *rna_path, int array_index, int scale=1);
   void unused_fcurve(std::vector<FCurve *> *curves);
   // prerequisites:
   // animlist_map - map animlist id -> animlist
diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp
index de66c6ebdb2..9bafc58a658 100644
--- a/source/blender/collada/ArmatureImporter.cpp
+++ b/source/blender/collada/ArmatureImporter.cpp
@@ -659,6 +659,11 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo &skin)
   ED_armature_from_edit(bmain, armature);
   ED_armature_edit_free(armature);
 
+  for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
+    COLLADAFW::Node *node = *ri;
+ 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list