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
This commit is contained in:
Gaia Clary 2014-02-03 13:04:51 +01:00
parent 4bd6423b7e
commit 89a846df51
4 changed files with 50 additions and 5 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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<COLLADAFW::UniqueId, COLLADAFW::Node*> root_map; // find root joint by child joint uid, for bone tree evaluation during resampling
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map;
std::string import_from_version;
};
#endif