Jelajahi Sumber

Classify STL file prefix using matchDataViewAt

Eran Geva 7 tahun lalu
induk
melakukan
303a954121
1 mengubah file dengan 14 tambahan dan 11 penghapusan
  1. 14 11
      examples/js/loaders/STLLoader.js

+ 14 - 11
examples/js/loaders/STLLoader.js

@@ -96,24 +96,27 @@ THREE.STLLoader.prototype = {
 
 			for ( var off = 0; off < 5; off ++ ) {
 
-				// Check if solid[ i ] matches the i-th byte at the current offset
+				// If "solid" text is matched to the current offset, declare it to be an ASCII STL.
 
-				var found = true;
-				for ( var i = 0; found && i < 5; i ++ ) {
+				if ( matchDataViewAt ( solid, reader, off ) ) return false;
 
-					found = found && ( solid[ i ] == reader.getUint8( off + i, false ) );
+			}
 
-				}
+			// Couldn't find "solid" text at the beginning; it is binary STL.
 
-				// Found "solid" text at the beginning; declare it to be an ASCII STL.
+			return true;
 
-				if ( found ) {
-					return false;
-				}
+		}
 
-			}
+		function matchDataViewAt( query, reader, offset ) {
 
-			// Couldn't find "solid" text at the beginning; it is binary STL.
+			// Check if each byte in query matches the corresponding byte from the current offset
+
+			for ( var i = 0, il = query.length; i < il; i ++ ) {
+
+				if ( query[ i ] !== reader.getUint8( offset + i, false ) ) return false;
+
+			}
 
 			return true;