소스 검색

Improve ability to detect the format of a STL file

For some reason, few binary STL files will have larger size than the value calculated based on metadata, causing them to be recognized as ASCII ones. To detect those files, a byte-by-byte check loop is added, it tries to find a non-ASCII character byte, if any is found, this file will be recognized as binary format.

The additional checking process slightly affected the loading time of ASCII files, for example a 78MB ASCII file will need 3 more seconds to go through the loop using a computer manufactured in 2012. However most mesh in this size will be encoded in binary format, so large ASCII file is uncommon.
Shun-An Lee 10 년 전
부모
커밋
bb64625533
1개의 변경된 파일20개의 추가작업 그리고 1개의 파일을 삭제
  1. 20 1
      examples/js/loaders/STLLoader.js

+ 20 - 1
examples/js/loaders/STLLoader.js

@@ -61,7 +61,26 @@ THREE.STLLoader.prototype = {
 			face_size = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
 			face_size = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
 			n_faces = reader.getUint32(80,true);
 			n_faces = reader.getUint32(80,true);
 			expect = 80 + (32 / 8) + (n_faces * face_size);
 			expect = 80 + (32 / 8) + (n_faces * face_size);
-			return expect === reader.byteLength;
+			
+			if ( expect === reader.byteLength ) {
+				
+				return true;
+				
+			}
+
+			var fileLength = reader.byteLength;
+
+			for ( var index = 0; index < fileLength; index ++ ) {
+
+				if ( reader.getUint8(index, false) > 127 ) {
+					
+					return true;
+					
+				}
+
+			}
+
+			return false;
 
 
 		};
 		};