fix T69772 Collada importer creates wrong fcurves for skeletal animation
authorGaia Clary <gaia.clary@machinimatrix.org>
Wed, 27 Nov 2019 10:18:10 +0000 (11:18 +0100)
committerGaia Clary <gaia.clary@machinimatrix.org>
Wed, 27 Nov 2019 10:18:38 +0000 (11:18 +0100)
source/blender/collada/AnimationImporter.cpp

index 9aebde095aa71bf1f8f978b02bc1a8f69af8773e..b17f647bf14fae9b3ac2cd1040addb136eedf231 100644 (file)
@@ -513,6 +513,24 @@ void AnimationImporter::find_frames(std::vector<float> *frames, std::vector<FCur
   }
 }
 
+static int get_animation_axis_index(const COLLADABU::Math::Vector3 &axis)
+{
+  int index;
+  if (COLLADABU::Math::Vector3::UNIT_X == axis) {
+    index = 0;
+  }
+  else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
+    index = 1;
+  }
+  else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
+    index = 2;
+  }
+  else {
+    index = -1;
+  }
+  return index;
+}
+
 /* creates the rna_paths and array indices of fcurves from animations using transformation and
  * bound animation class of each animation. */
 void AnimationImporter::Assign_transform_animations(
@@ -592,30 +610,15 @@ void AnimationImporter::Assign_transform_animations(
       COLLADABU::Math::Vector3 &axis = rot->getRotationAxis();
 
       switch (binding->animationClass) {
-        case COLLADAFW::AnimationList::ANGLE:
-          if (COLLADABU::Math::Vector3::UNIT_X == axis) {
-            modify_fcurve(curves, rna_path, 0);
-          }
-          else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
-            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) {
-            if (is_joint) {
-              modify_fcurve(curves, rna_path, 1);  // Bone animation from dae to blender
-            }
-            else {
-              modify_fcurve(curves, rna_path, 2);
-            }
+        case COLLADAFW::AnimationList::ANGLE: {
+          int axis_index = get_animation_axis_index(axis);
+          if (axis_index >= 0) {
+            modify_fcurve(curves, rna_path, axis_index);
           }
           else {
             unused_fcurve(curves);
           }
-          break;
+        } break;
         case COLLADAFW::AnimationList::AXISANGLE:
         /* TODO convert axis-angle to quat? or XYZ? */
         default: