|
@@ -1,6 +1,8 @@
|
|
|
import { Cache } from './Cache.js';
|
|
import { Cache } from './Cache.js';
|
|
|
import { Loader } from './Loader.js';
|
|
import { Loader } from './Loader.js';
|
|
|
|
|
|
|
|
|
|
+const _errorMap = new WeakMap();
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* A loader for loading images as an [ImageBitmap]{@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap}.
|
|
* A loader for loading images as an [ImageBitmap]{@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap}.
|
|
|
* An `ImageBitmap` provides an asynchronous and resource efficient pathway to prepare
|
|
* An `ImageBitmap` provides an asynchronous and resource efficient pathway to prepare
|
|
@@ -11,7 +13,7 @@ import { Loader } from './Loader.js';
|
|
|
*
|
|
*
|
|
|
* You need to set the equivalent options via {@link ImageBitmapLoader#setOptions} instead.
|
|
* You need to set the equivalent options via {@link ImageBitmapLoader#setOptions} instead.
|
|
|
*
|
|
*
|
|
|
- * Also note that unlike {@link FileLoader}, this loader does not avoid multiple concurrent requests to the same URL.
|
|
|
|
|
|
|
+ * Also note that unlike {@link FileLoader}, this loader avoids multiple concurrent requests to the same URL only if `Cache` is enabled.
|
|
|
*
|
|
*
|
|
|
* ```js
|
|
* ```js
|
|
|
* const loader = new THREE.ImageBitmapLoader();
|
|
* const loader = new THREE.ImageBitmapLoader();
|
|
@@ -111,15 +113,27 @@ class ImageBitmapLoader extends Loader {
|
|
|
|
|
|
|
|
cached.then( imageBitmap => {
|
|
cached.then( imageBitmap => {
|
|
|
|
|
|
|
|
- if ( onLoad ) onLoad( imageBitmap );
|
|
|
|
|
|
|
+ // check if there is an error for the cached promise
|
|
|
|
|
+
|
|
|
|
|
+ if ( _errorMap.has( cached ) === true ) {
|
|
|
|
|
+
|
|
|
|
|
+ if ( onError ) onError( _errorMap.get( cached ) );
|
|
|
|
|
+
|
|
|
|
|
+ scope.manager.itemError( url );
|
|
|
|
|
+ scope.manager.itemEnd( url );
|
|
|
|
|
|
|
|
- scope.manager.itemEnd( url );
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
|
|
- } ).catch( e => {
|
|
|
|
|
|
|
+ if ( onLoad ) onLoad( imageBitmap );
|
|
|
|
|
|
|
|
- if ( onError ) onError( e );
|
|
|
|
|
|
|
+ scope.manager.itemEnd( url );
|
|
|
|
|
+
|
|
|
|
|
+ return imageBitmap;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -163,6 +177,8 @@ class ImageBitmapLoader extends Loader {
|
|
|
|
|
|
|
|
if ( onError ) onError( e );
|
|
if ( onError ) onError( e );
|
|
|
|
|
|
|
|
|
|
+ _errorMap.set( promise, e );
|
|
|
|
|
+
|
|
|
Cache.remove( url );
|
|
Cache.remove( url );
|
|
|
|
|
|
|
|
scope.manager.itemError( url );
|
|
scope.manager.itemError( url );
|