Browse Source

FBXLoader - Speed up getTimesForAllAxes

Kimbatt 4 năm trước cách đây
mục cha
commit
7c375d95aa
2 tập tin đã thay đổi với 44 bổ sung8 xóa
  1. 22 4
      examples/js/loaders/FBXLoader.js
  2. 22 4
      examples/jsm/loaders/FBXLoader.js

+ 22 - 4
examples/js/loaders/FBXLoader.js

@@ -2790,16 +2790,34 @@ THREE.FBXLoader = ( function () {
 			if ( curves.y !== undefined ) times = times.concat( curves.y.times );
 			if ( curves.z !== undefined ) times = times.concat( curves.z.times );
 
-			// then sort them and remove duplicates
+			// then sort them
 			times = times.sort( function ( a, b ) {
 
 				return a - b;
 
-			} ).filter( function ( elem, index, array ) {
+			} );
 
-				return array.indexOf( elem ) == index;
+			// and remove duplicates
+			if ( times.length > 1 ) {
 
-			} );
+				var targetIndex = 1;
+				var lastValue = times[ 0 ];
+				for ( var i = 1; i < times.length; i ++ ) {
+
+					var currentValue = times[ i ];
+					if ( currentValue !== lastValue ) {
+
+						times[ targetIndex ] = currentValue;
+						lastValue = currentValue;
+						targetIndex ++;
+
+					}
+
+				}
+
+				times = times.slice( 0, targetIndex );
+
+			}
 
 			return times;
 

+ 22 - 4
examples/jsm/loaders/FBXLoader.js

@@ -2837,16 +2837,34 @@ var FBXLoader = ( function () {
 			if ( curves.y !== undefined ) times = times.concat( curves.y.times );
 			if ( curves.z !== undefined ) times = times.concat( curves.z.times );
 
-			// then sort them and remove duplicates
+			// then sort them
 			times = times.sort( function ( a, b ) {
 
 				return a - b;
 
-			} ).filter( function ( elem, index, array ) {
+			} );
 
-				return array.indexOf( elem ) == index;
+			// and remove duplicates
+			if ( times.length > 1 ) {
 
-			} );
+				var targetIndex = 1;
+				var lastValue = times[ 0 ];
+				for ( var i = 1; i < times.length; i ++ ) {
+
+					var currentValue = times[ i ];
+					if ( currentValue !== lastValue ) {
+
+						times[ targetIndex ] = currentValue;
+						lastValue = currentValue;
+						targetIndex ++;
+
+					}
+
+				}
+
+				times = times.slice( 0, targetIndex );
+
+			}
 
 			return times;