浏览代码

BasisTextureLoader: use url as task key in task cache

Senya Pugach 5 年之前
父节点
当前提交
c520332335
共有 2 个文件被更改,包括 4 次插入38 次删除
  1. 2 19
      examples/js/loaders/BasisTextureLoader.js
  2. 2 19
      examples/jsm/loaders/BasisTextureLoader.js

+ 2 - 19
examples/js/loaders/BasisTextureLoader.js

@@ -112,31 +112,16 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
 
 
 		loader.load( url, ( buffer ) => {
 		loader.load( url, ( buffer ) => {
 
 
-			var taskKey = JSON.stringify( url );
-
 			// Check for an existing task using this buffer. A transferred buffer cannot be transferred
 			// Check for an existing task using this buffer. A transferred buffer cannot be transferred
 			// again from this thread.
 			// again from this thread.
 			if ( THREE.BasisTextureLoader.taskCache.has( buffer ) ) {
 			if ( THREE.BasisTextureLoader.taskCache.has( buffer ) ) {
 
 
 				var cachedTask = THREE.BasisTextureLoader.taskCache.get( buffer );
 				var cachedTask = THREE.BasisTextureLoader.taskCache.get( buffer );
 
 
-				if ( cachedTask.key === taskKey ) {
+				if ( cachedTask.url === url ) {
 
 
 					return cachedTask.promise.then( onLoad ).catch( onError );
 					return cachedTask.promise.then( onLoad ).catch( onError );
 
 
-				} else if ( buffer.byteLength === 0 ) {
-
-					// Technically, it would be possible to wait for the previous task to complete,
-					// transfer the buffer back, and decode again with the second configuration. That
-					// is complex, and I don't know of any reason to decode a Basis buffer twice in
-					// different ways, so this is left unimplemented.
-					throw new Error(
-
-						'THREE.BasisTextureLoader: Unable to re-decode a buffer with different ' +
-						'settings. Buffer has already been transferred.'
-
-					);
-
 				}
 				}
 
 
 			}
 			}
@@ -233,12 +218,10 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
 
 
 			} );
 			} );
 
 
-		var taskKey = JSON.stringify( url );
-
 		// Cache the task result.
 		// Cache the task result.
 		THREE.BasisTextureLoader.taskCache.set( buffer, {
 		THREE.BasisTextureLoader.taskCache.set( buffer, {
 
 
-			key: taskKey,
+			url: url,
 			promise: texturePending
 			promise: texturePending
 
 
 		} );
 		} );

+ 2 - 19
examples/jsm/loaders/BasisTextureLoader.js

@@ -125,31 +125,16 @@ BasisTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 
 		loader.load( url, ( buffer ) => {
 		loader.load( url, ( buffer ) => {
 
 
-			var taskKey = JSON.stringify( url );
-
 			// Check for an existing task using this buffer. A transferred buffer cannot be transferred
 			// Check for an existing task using this buffer. A transferred buffer cannot be transferred
 			// again from this thread.
 			// again from this thread.
 			if ( BasisTextureLoader.taskCache.has( buffer ) ) {
 			if ( BasisTextureLoader.taskCache.has( buffer ) ) {
 
 
 				var cachedTask = BasisTextureLoader.taskCache.get( buffer );
 				var cachedTask = BasisTextureLoader.taskCache.get( buffer );
 
 
-				if ( cachedTask.key === taskKey ) {
+				if ( cachedTask.url === url ) {
 
 
 					return cachedTask.promise.then( onLoad ).catch( onError );
 					return cachedTask.promise.then( onLoad ).catch( onError );
 
 
-				} else if ( buffer.byteLength === 0 ) {
-
-					// Technically, it would be possible to wait for the previous task to complete,
-					// transfer the buffer back, and decode again with the second configuration. That
-					// is complex, and I don't know of any reason to decode a Basis buffer twice in
-					// different ways, so this is left unimplemented.
-					throw new Error(
-
-						'THREE.BasisTextureLoader: Unable to re-decode a buffer with different ' +
-						'settings. Buffer has already been transferred.'
-
-					);
-
 				}
 				}
 
 
 			}
 			}
@@ -246,12 +231,10 @@ BasisTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
 
 
 			} );
 			} );
 
 
-		var taskKey = JSON.stringify( url );
-
 		// Cache the task result.
 		// Cache the task result.
 		BasisTextureLoader.taskCache.set( buffer, {
 		BasisTextureLoader.taskCache.set( buffer, {
 
 
-			key: taskKey,
+			url: url,
 			promise: texturePending
 			promise: texturePending
 
 
 		} );
 		} );