diff options
author | gaiaclary <gaia.clary@machinimatrix.org> | 2014-02-03 16:04:51 +0400 |
---|---|---|
committer | gaiaclary <gaia.clary@machinimatrix.org> | 2014-02-03 16:04:51 +0400 |
commit | 89a846df51224ff829b8683dad93024e0b230319 (patch) | |
tree | a402b644ac5f373dd6e23bc4430316cd01d3ef61 /source/blender/collada/DocumentImporter.cpp | |
parent | 4bd6423b7efdb3a4d1c18d15af3cdc9d7f2e41b7 (diff) |
Add compatibility for older Collada files
The Fix in 273 creates a backward incompatibility:
Collada files that have been created with an older Blender version
will contain the spotlight_size in Radians where Collada wants
this value to be in DEGREE.
This fix adds a check for the Blender Version that was used to create the
Collada file. If the Collada file was made by an older version of Blender
then the importer will assume that spotlight_size is specified in RADIANS.
Reviewers: campbellbarton, sauraedron
Reviewed By: sauraedron
CC: jesterking
Differential Revision: https://developer.blender.org/D279
Diffstat (limited to 'source/blender/collada/DocumentImporter.cpp')
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
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; } |