diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index 66312f7299f..d27795b0ab2 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -648,12 +648,17 @@ 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 (strcmp("spot_size", anim_type)==0) { + /* 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); } } @@ -2011,3 +2016,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; +} diff --git a/source/blender/collada/AnimationImporter.h b/source/blender/collada/AnimationImporter.h index 61c220e4bbe..565fe183d02 100644 --- a/source/blender/collada/AnimationImporter.h +++ b/source/blender/collada/AnimationImporter.h @@ -89,6 +89,8 @@ private: int typeFlag; + std::string import_from_version; + enum lightAnim { // INANIMATE = 0, @@ -137,6 +139,7 @@ public: ~AnimationImporter(); + void set_import_from_version(std::string import_from_version); bool write_animation(const COLLADAFW::Animation* anim); // called on post-process stage after writeVisualScenes diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index f8fc035f620..ea0f6cf0049 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -326,12 +326,43 @@ void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW } } +/** + * If the imported file was made with Blender, return the Blender version used, + * otherwise return an empty std::string + */ +std::string DocumentImporter::get_import_version(const COLLADAFW::FileInfo *asset) +{ + const char AUTORING_TOOL[] = "authoring_tool"; + const std::string BLENDER("Blender "); + const COLLADAFW::FileInfo::ValuePairPointerArray &valuePairs = asset->getValuePairArray(); + for ( size_t i = 0, count = valuePairs.getCount(); i < count; ++i) + { + const COLLADAFW::FileInfo::ValuePair* valuePair = valuePairs[i]; + const COLLADAFW::String& key = valuePair->first; + const COLLADAFW::String& value = valuePair->second; + if ( key == AUTORING_TOOL ) + { + if (value.compare(0, BLENDER.length(), BLENDER) == 0) + { + // Was made with Blender, now get version string + std::string v = value.substr(BLENDER.length()); + std::string::size_type n = v.find(" "); + if (n > 0) { + return v.substr(0,n); + } + } + } + } + return ""; +} + /** When this method is called, the writer must write the global document asset. * \return The writer should return true, if writing succeeded, false otherwise.*/ bool DocumentImporter::writeGlobalAsset(const COLLADAFW::FileInfo *asset) { unit_converter.read_asset(asset); - + import_from_version = get_import_version(asset); + anim_importer.set_import_from_version(import_from_version); return true; } diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h index ff0cbd44043..96aa7eb4578 100644 --- a/source/blender/collada/DocumentImporter.h +++ b/source/blender/collada/DocumentImporter.h @@ -97,6 +97,7 @@ public: void finish(); bool writeGlobalAsset(const COLLADAFW::FileInfo*); + std::string get_import_version(const COLLADAFW::FileInfo *asset); bool writeScene(const COLLADAFW::Scene*); @@ -169,6 +170,7 @@ private: std::map root_map; // find root joint by child joint uid, for bone tree evaluation during resampling std::map FW_object_map; + std::string import_from_version; }; #endif