[Bf-blender-cvs] [89a846d] master: Add compatibility for older Collada files

gaiaclary noreply at git.blender.org
Mon Feb 3 13:04:57 CET 2014


Commit: 89a846df51224ff829b8683dad93024e0b230319
Author: gaiaclary
Date:   Mon Feb 3 13:04:51 2014 +0100
https://developer.blender.org/rB89a846df51224ff829b8683dad93024e0b230319

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

===================================================================

M	source/blender/collada/AnimationImporter.cpp
M	source/blender/collada/AnimationImporter.h
M	source/blender/collada/DocumentImporter.cpp
M	source/blender/collada/DocumentImporter.h

===================================================================

diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp
index 66312f7..d27795b 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 61c220e..565fe18 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 f8fc035..ea0f6cf 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 ff0cbd4..96aa7eb 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<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




More information about the Bf-blender-cvs mailing list