Prechádzať zdrojové kódy

FBX 7.5+ support: Some fields now Int64 (#405)

Pavel Alexandrov 7 rokov pred
rodič
commit
6a2a855379
1 zmenil súbory, kde vykonal 19 pridanie a 9 odobranie
  1. 19 9
      hxd/fmt/fbx/Parser.hx

+ 19 - 9
hxd/fmt/fbx/Parser.hx

@@ -23,7 +23,8 @@ class Parser {
 	var pos : Int;
 	var pos : Int;
 	var token : Null<Token>;
 	var token : Null<Token>;
 	var binary : Bool;
 	var binary : Bool;
-
+	var fbxVersion:Int;
+	
 	function new() {
 	function new() {
 	}
 	}
 
 
@@ -49,17 +50,19 @@ class Parser {
 		token = null;
 		token = null;
 		if (this.binary) {
 		if (this.binary) {
 			// Skip header, magic [0x1A, 0x00] and version number.
 			// Skip header, magic [0x1A, 0x00] and version number.
+			fbxVersion = bytes.getInt32(0x17);
+			
 			this.pos = 21 + 2 + 4;
 			this.pos = 21 + 2 + 4;
-			var firstNode = parseBinaryNode(getInt32());
+			var firstNode = parseBinaryNode(getVersionedInt32());
 			if (firstNode.name != "") {
 			if (firstNode.name != "") {
 				
 				
 				// Root was omitted, read until all data obtained.
 				// Root was omitted, read until all data obtained.
 				var nodes : Array<FbxNode> = [firstNode];
 				var nodes : Array<FbxNode> = [firstNode];
-				var size:Int = getInt32();
+				var size:Int = getVersionedInt32();
 				
 				
 				while (size != 0) {
 				while (size != 0) {
 					nodes.push(parseBinaryNode(size));
 					nodes.push(parseBinaryNode(size));
-					size = getInt32();
+					size = getVersionedInt32();
 				}
 				}
 				
 				
 				return {
 				return {
@@ -171,18 +174,18 @@ class Parser {
 	}
 	}
 	
 	
 	function parseBinaryNodes( output : Array<FbxNode> ) {
 	function parseBinaryNodes( output : Array<FbxNode> ) {
-		var size : Int = getInt32();
+		var size : Int = getVersionedInt32();
 		while (size != 0)
 		while (size != 0)
 		{
 		{
 			output.push(parseBinaryNode(size));
 			output.push(parseBinaryNode(size));
-			size = getInt32();
+			size = getVersionedInt32();
 		}
 		}
 	}
 	}
 	
 	
 	function parseBinaryNode( nextRecord : Int ) : FbxNode {
 	function parseBinaryNode( nextRecord : Int ) : FbxNode {
 		
 		
-		var numProperties : Int = getInt32();
-		var propertyListLength : UInt = getInt32();
+		var numProperties : Int = getVersionedInt32();
+		var propertyListLength : UInt = getVersionedInt32();
 		var nameLen : Int = getByte();
 		var nameLen : Int = getByte();
 		var name : String = (nameLen == 0 ? "" : bytes.getString(pos, nameLen));
 		var name : String = (nameLen == 0 ? "" : bytes.getString(pos, nameLen));
 		pos += nameLen;
 		pos += nameLen;
@@ -354,7 +357,14 @@ class Parser {
 	inline function nextChar() {
 	inline function nextChar() {
 		return StringTools.fastCodeAt(buf, pos++);
 		return StringTools.fastCodeAt(buf, pos++);
 	}
 	}
-
+	
+	inline function getVersionedInt32() {
+		var i : Int = bytes.getInt32(pos);
+		// No support for file sizes over Int32.
+		pos += fbxVersion >= 7500 ? 8 : 4;
+		return i;
+	}
+	
 	inline function getInt32() {
 	inline function getInt32() {
 		var i : Int = bytes.getInt32(pos);
 		var i : Int = bytes.getInt32(pos);
 		pos += 4;
 		pos += 4;