Browse Source

- fbx: add "strict" import mode (only accept 2012,2013 files).

Alexander Gessler 13 years ago
parent
commit
f617e766b1
2 changed files with 19 additions and 2 deletions
  1. 9 2
      code/FBXDocument.cpp
  2. 10 0
      code/FBXImportSettings.h

+ 9 - 2
code/FBXDocument.cpp

@@ -494,9 +494,9 @@ const Object* LazyObject::Get(bool dieOnError)
 		flags &= ~BEING_CONSTRUCTED;
 		flags &= ~BEING_CONSTRUCTED;
 		flags |= FAILED_TO_CONSTRUCT;
 		flags |= FAILED_TO_CONSTRUCT;
 
 
-		//if(dieOnError) {
+		if(dieOnError || doc.Settings().strictMode) {
 			throw;
 			throw;
-		//}
+		}
 
 
 		// note: the error message is already formatted, so raw logging is ok
 		// note: the error message is already formatted, so raw logging is ok
 		if(!DefaultLogger::isNullLogger()) {
 		if(!DefaultLogger::isNullLogger()) {
@@ -587,6 +587,13 @@ void Document::ReadHeader()
 	const Scope& shead = *ehead->Compound();
 	const Scope& shead = *ehead->Compound();
 	fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
 	fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
 
 
+	if(Settings().strictMode) {
+		if(fbxVersion < 7200 || fbxVersion > 7300) {
+			DOMError("unsupported format version, supported are only FBX 2012 and FBX 2013"\
+				" in ASCII format (turn off strict mode to try anyhow) ");
+		}
+	}
+
 	const Element* const ecreator = shead["Creator"];
 	const Element* const ecreator = shead["Creator"];
 	if(ecreator) {
 	if(ecreator) {
 		creator = ParseTokenAsString(GetRequiredToken(*ecreator,0));
 		creator = ParseTokenAsString(GetRequiredToken(*ecreator,0));

+ 10 - 0
code/FBXImportSettings.h

@@ -57,7 +57,17 @@ struct ImportSettings
 		, readCameras(true)
 		, readCameras(true)
 		, readLights(true)
 		, readLights(true)
 		, readAnimations(true)
 		, readAnimations(true)
+		, strictMode(true)
 	{}
 	{}
+ 
+
+	/** enable strict mode:
+	 *   - only accept fbx 2012, 2013 files
+	 *   - on the slightest error, give up.
+	 *
+	 *  Basically, strict mode means that the fbx file will actually
+	 *  be validated. Strict mode is off by default. */
+	bool strictMode;
 
 
 	/** specifies whether all geometry layers are read and scanned for
 	/** specifies whether all geometry layers are read and scanned for
 	  * usable data channels. The FBX spec indicates that many readers
 	  * usable data channels. The FBX spec indicates that many readers