Cleanup: warning & whitespace
[blender.git] / source / blender / collada / AnimationImporter.cpp
index 66312f7299f2944ddd6795325c4a45c27cf7857e..5cd01eff2633720297086905b51539b99cc75f80 100644 (file)
@@ -38,7 +38,7 @@
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 
-#include "BLF_translation.h"
+#include "BLT_translation.h"
 
 #include "BKE_action.h"
 #include "BKE_armature.h"
@@ -153,15 +153,13 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
                                calchandles_fcurve(fcu);
 
                                fcurves.push_back(fcu);
+                               unused_curves.push_back(fcu);
                        }
                }
                break;
                default:
                        fprintf(stderr, "Output dimension of %d is not yet supported (animation id = %s)\n", (int)dim, curve->getOriginalId().c_str());
        }
-
-       for (std::vector<FCurve *>::iterator it = fcurves.begin(); it != fcurves.end(); it++)
-               unused_curves.push_back(*it);
 }
 
 
@@ -175,6 +173,11 @@ void AnimationImporter::fcurve_deg_to_rad(FCurve *cu)
        }
 }
 
+void AnimationImporter::fcurve_is_used(FCurve *fcu)
+{
+       unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu), unused_curves.end());
+}
+
 
 void AnimationImporter::add_fcurves_to_object(Object *ob, std::vector<FCurve *>& curves, char *rna_path, int array_index, Animation *animated)
 {
@@ -219,12 +222,13 @@ void AnimationImporter::add_fcurves_to_object(Object *ob, std::vector<FCurve *>&
                                        BLI_strncpy(grp->name, bone_name, sizeof(grp->name));
                                        
                                        BLI_addtail(&act->groups, grp);
-                                       BLI_uniquename(&act->groups, grp, CTX_DATA_(BLF_I18NCONTEXT_ID_ACTION, "Group"), '.',
+                                       BLI_uniquename(&act->groups, grp, CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "Group"), '.',
                                                       offsetof(bActionGroup, name), 64);
                                }
                                
                                /* add F-Curve to group */
                                action_groups_add_channel(act, grp, fcu);
+                               fcurve_is_used(fcu);
                                
                        }
 #if 0
@@ -235,10 +239,8 @@ void AnimationImporter::add_fcurves_to_object(Object *ob, std::vector<FCurve *>&
                }
                else {
                        BLI_addtail(&act->curves, fcu);
+                       fcurve_is_used(fcu);
                }
-
-               // curve is used, so remove it from unused_curves
-               unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu), unused_curves.end());
        }
 }
 
@@ -438,7 +440,7 @@ void AnimationImporter::modify_fcurve(std::vector<FCurve *> *curves, const char
                if (array_index == -1) fcu->array_index = i;
                else fcu->array_index = array_index;
 
-               unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu), unused_curves.end());
+               fcurve_is_used(fcu);
        }
 }
 
@@ -448,7 +450,7 @@ void AnimationImporter::unused_fcurve(std::vector<FCurve *> *curves)
        std::vector<FCurve *>::iterator it;
        for (it = curves->begin(); it != curves->end(); it++) {
                FCurve *fcu = *it;
-               unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu), unused_curves.end());
+               fcurve_is_used(fcu);
        }
 }
 
@@ -621,10 +623,9 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
                for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
                        FCurve *fcu = *iter;
                        BLI_addtail(AnimCurves, fcu);
+                       fcurve_is_used(fcu);
                }
        }
-
-
 }
 
 void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char *anim_type)
@@ -648,13 +649,19 @@ void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& list
                        //Add the curves of the current animation to the object
                        for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
                                FCurve *fcu = *iter;
-                               /* All anim_types whose values are to be converted from Degree to Radians can be ORed here
-                                *XXX What About " rotation " ? */
-                               if (BLI_strcaseeq("spot_size", anim_type))      {
-                                               /* Convert current values to Radians */
+                               /* All anim_types whose values are to be converted from Degree to Radians can be ORed here */
+                               if (STREQ("spot_size", anim_type)) {
+                                       /* NOTE: Do NOT convert if imported file was made by blender <= 2.69.10
+                                        * Reason: old blender versions stored spot_size in radians (was a bug)
+                                        */
+                                       if (this->import_from_version == "" || BLI_natstrcmp(this->import_from_version.c_str(), "2.69.10") != -1) {
                                                fcurve_deg_to_rad(fcu);
+                                       }
                                }
+                               /** XXX What About animtype "rotation" ? */
+
                                BLI_addtail(AnimCurves, fcu);
+                               fcurve_is_used(fcu);
                        }
                }
        }
@@ -700,6 +707,7 @@ void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId& listid
                                }
 
                                BLI_addtail(AnimCurves, fcu);
+                               fcurve_is_used(fcu);
                        }
                }
        }
@@ -799,7 +807,7 @@ void AnimationImporter::apply_matrix_curves(Object *ob, std::vector<FCurve *>& a
                        // evaluate_joint_world_transform_at_frame(temp, NULL, node, fra);
 
                        // calc special matrix
-                       mul_serie_m4(mat, irest, temp, irest_dae, rest, NULL, NULL, NULL, NULL);
+                       mul_m4_series(mat, irest, temp, irest_dae, rest);
                }
                else {
                        copy_m4_m4(mat, matfra);
@@ -835,8 +843,10 @@ void AnimationImporter::apply_matrix_curves(Object *ob, std::vector<FCurve *>& a
                        add_bone_fcurve(ob, node, newcu[i]);
                else
                        BLI_addtail(curves, newcu[i]);
+               // fcurve_is_used(newcu[i]);  // never added to unused
        }
 
+
        if (is_joint) {
                bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name);
                chan->rotmode = ROT_MODE_QUAT;
@@ -886,8 +896,6 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node,
                                              std::multimap<COLLADAFW::UniqueId, Object *>& object_map,
                                              std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map)
 {
-       AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map);
-
        bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
        COLLADAFW::UniqueId uid = node->getUniqueId();
        COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ? node : root_map[uid];
@@ -903,6 +911,8 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node,
                return;
        }
 
+
+       AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map);
        bAction *act;
 
        if ( (animType->transform) != 0) {
@@ -961,6 +971,7 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node,
                                                                FCurve *fcu = *iter;
                                                        
                                                                BLI_addtail(AnimCurves, fcu);
+                                                               fcurve_is_used(fcu);
                                                        }
                                                }
                                                
@@ -1103,6 +1114,8 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node,
                        }
                }
        }
+
+       delete animType;
 }
 
 void AnimationImporter::add_bone_animation_sampled(Object *ob, std::vector<FCurve *>& animcurves, COLLADAFW::Node *root, COLLADAFW::Node *node, COLLADAFW::Transformation *tm)
@@ -1205,7 +1218,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, std::vector<FCurv
                // evaluate_joint_world_transform_at_frame(temp, NULL, node, fra);
 
                // calc special matrix
-               mul_serie_m4(mat, irest, temp, irest_dae, rest, NULL, NULL, NULL, NULL);
+               mul_m4_series(mat, irest, temp, irest_dae, rest);
 
                float rot[4], loc[3], scale[3];
 
@@ -1228,6 +1241,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, std::vector<FCurv
        // add curves
        for (int i = 0; i < totcu; i++) {
                add_bone_fcurve(ob, node, newcu[i]);
+               // fcurve_is_used(newcu[i]);  // never added to unused
        }
 
        bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name);
@@ -1540,7 +1554,7 @@ Object *AnimationImporter::translate_animation_OLD(COLLADAFW::Node *node,
                        // evaluate_joint_world_transform_at_frame(temp, NULL, node, fra);
 
                        // calc special matrix
-                       mul_serie_m4(mat, irest, temp, irest_dae, rest, NULL, NULL, NULL, NULL);
+                       mul_m4_series(mat, irest, temp, irest_dae, rest);
                }
                else {
                        copy_m4_m4(mat, matfra);
@@ -1827,7 +1841,7 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float
                                                i++;
                                                j = 0;
                                        }
-                                       unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), *it), unused_curves.end());
+                                       fcurve_is_used(*it);
                                }
 
                                COLLADAFW::Matrix tm(matrix);
@@ -1989,7 +2003,7 @@ void AnimationImporter::add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurv
                BLI_strncpy(grp->name, bone_name, sizeof(grp->name));
 
                BLI_addtail(&act->groups, grp);
-               BLI_uniquename(&act->groups, grp, CTX_DATA_(BLF_I18NCONTEXT_ID_ACTION, "Group"), '.',
+               BLI_uniquename(&act->groups, grp, CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "Group"), '.',
                               offsetof(bActionGroup, name), 64);
        }
 
@@ -2011,3 +2025,7 @@ void AnimationImporter::add_bezt(FCurve *fcu, float fra, float value)
        calchandles_fcurve(fcu);
 }
 
+void AnimationImporter::set_import_from_version(std::string import_from_version)
+{
+       this->import_from_version = import_from_version;
+}