From eb77f9e6757c691919223dab4f58d80a6cc6af73 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Wed, 22 Dec 2021 22:31:52 +0100 Subject: [PATCH] Fix #20705 Ability to cancel ongoing HTTP requests in loaders --- docs/api/en/loaders/AnimationLoader.html | 7 ++++--- docs/api/en/loaders/AudioLoader.html | 7 ++++--- docs/api/en/loaders/BufferGeometryLoader.html | 7 ++++--- docs/api/en/loaders/CompressedTextureLoader.html | 7 ++++--- docs/api/en/loaders/CubeTextureLoader.html | 7 ++++--- docs/api/en/loaders/DataTextureLoader.html | 7 ++++--- docs/api/en/loaders/FileLoader.html | 10 +++++----- docs/api/en/loaders/ImageBitmapLoader.html | 7 ++++--- docs/api/en/loaders/ImageLoader.html | 4 ++-- docs/api/en/loaders/Loader.html | 5 +++-- docs/api/en/loaders/MaterialLoader.html | 7 ++++--- docs/api/en/loaders/ObjectLoader.html | 7 ++++--- docs/api/en/loaders/TextureLoader.html | 4 ++-- src/loaders/AnimationLoader.js | 4 ++-- src/loaders/AudioLoader.js | 4 ++-- src/loaders/BufferGeometryLoader.js | 4 ++-- src/loaders/CompressedTextureLoader.js | 6 +++--- src/loaders/CubeTextureLoader.js | 4 ++-- src/loaders/DataTextureLoader.js | 4 ++-- src/loaders/FileLoader.js | 7 ++++--- src/loaders/ImageBitmapLoader.js | 3 ++- src/loaders/Loader.js | 6 +++--- src/loaders/MaterialLoader.js | 4 ++-- src/loaders/ObjectLoader.js | 4 ++-- 24 files changed, 74 insertions(+), 62 deletions(-) diff --git a/docs/api/en/loaders/AnimationLoader.html b/docs/api/en/loaders/AnimationLoader.html index f2a95a19ec7867..edb67b3ba8d024 100644 --- a/docs/api/en/loaders/AnimationLoader.html +++ b/docs/api/en/loaders/AnimationLoader.html @@ -59,13 +59,14 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:AnimationClip animation clips].
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called if load errors.

+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called if load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and pass the loaded animation to onLoad.

diff --git a/docs/api/en/loaders/AudioLoader.html b/docs/api/en/loaders/AudioLoader.html index a3f97e4c860dab..f7f68449d2ccc6 100644 --- a/docs/api/en/loaders/AudioLoader.html +++ b/docs/api/en/loaders/AudioLoader.html @@ -76,13 +76,14 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded text response.
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and pass the loaded [page:String AudioBuffer] to onLoad. diff --git a/docs/api/en/loaders/BufferGeometryLoader.html b/docs/api/en/loaders/BufferGeometryLoader.html index f475c23210094e..d2041ccf906186 100644 --- a/docs/api/en/loaders/BufferGeometryLoader.html +++ b/docs/api/en/loaders/BufferGeometryLoader.html @@ -68,13 +68,14 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].d
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:BufferGeometry].
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and call onLoad with the parsed response content. diff --git a/docs/api/en/loaders/CompressedTextureLoader.html b/docs/api/en/loaders/CompressedTextureLoader.html index 978badddda549f..3c425d358900ed 100644 --- a/docs/api/en/loaders/CompressedTextureLoader.html +++ b/docs/api/en/loaders/CompressedTextureLoader.html @@ -40,13 +40,14 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:CompressedTexture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:CompressedTexture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded texture.
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and pass the loaded texture to onLoad. diff --git a/docs/api/en/loaders/CubeTextureLoader.html b/docs/api/en/loaders/CubeTextureLoader.html index 65c64ca15e159e..76149794e84b14 100644 --- a/docs/api/en/loaders/CubeTextureLoader.html +++ b/docs/api/en/loaders/CubeTextureLoader.html @@ -55,7 +55,7 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:CubeTexture load]( [param:String urls], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:CubeTexture load]( [param:String urls], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String urls] — array of 6 urls to images, one for each side of the CubeTexture. The urls should be specified in the following order: pos-x, neg-x, pos-y, neg-y, pos-z, neg-z. @@ -64,8 +64,9 @@

[method:CubeTexture load]( [param:String urls], [param:Function onLoad], [pa when looking up the positive-z axis -- in other words, using a left-handed coordinate system. Since three.js uses a right-handed coordinate system, environment maps used in three.js will have pos-x and neg-x swapped.
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Texture texture].
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — This callback function is currently not supported.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and pass the loaded [page:CubeTexture texture] to onLoad. diff --git a/docs/api/en/loaders/DataTextureLoader.html b/docs/api/en/loaders/DataTextureLoader.html index 715677a814d7c4..eab51b84452250 100644 --- a/docs/api/en/loaders/DataTextureLoader.html +++ b/docs/api/en/loaders/DataTextureLoader.html @@ -40,13 +40,14 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:DataTexture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:DataTexture load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded texture.
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — Will be called while load progresses.The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and pass the loaded texture to onLoad. diff --git a/docs/api/en/loaders/FileLoader.html b/docs/api/en/loaders/FileLoader.html index 2eb00d3d433d73..de5bdc384ee6df 100644 --- a/docs/api/en/loaders/FileLoader.html +++ b/docs/api/en/loaders/FileLoader.html @@ -12,7 +12,7 @@

[name]

- A low level class for loading resources with XMLHttpRequest, used internaly by most loaders. + A low level class for loading resources with Fetch, used internaly by most loaders. It can also be used directly to load any file type that does not have a loader.

@@ -74,14 +74,14 @@

[property:String responseType]

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] (optional) — Will be called when loading completes. The argument will be the loaded response.
- [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the XMLHttpRequest instance, - which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] (optional) — Will be called if an error occurs.

+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called if an error occurs.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Load the URL and pass the response to the onLoad function.

diff --git a/docs/api/en/loaders/ImageBitmapLoader.html b/docs/api/en/loaders/ImageBitmapLoader.html index 580eb771d53459..7b6f49e9bb64c8 100644 --- a/docs/api/en/loaders/ImageBitmapLoader.html +++ b/docs/api/en/loaders/ImageBitmapLoader.html @@ -78,13 +78,14 @@

[property:String options]

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].
- [page:Function onProgress] — This callback function is currently not supported.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — This callback function is currently not supported.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and return the [page:ImageBitmap image] object that will contain the data. diff --git a/docs/api/en/loaders/ImageLoader.html b/docs/api/en/loaders/ImageLoader.html index 24a7def254d091..6eb1b1306e9f41 100644 --- a/docs/api/en/loaders/ImageLoader.html +++ b/docs/api/en/loaders/ImageLoader.html @@ -78,8 +78,8 @@

[method:HTMLImageElement load]( [param:String url], [param:Function onLoad], [page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Image image].
- [page:Function onProgress] — This callback function is currently not supported.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — This callback function is currently not supported.
+ [page:Function onError] (optional) — Will be called when load errors.

Begin loading from url and return the [page:Image image] object that will contain the data. diff --git a/docs/api/en/loaders/Loader.html b/docs/api/en/loaders/Loader.html index 7fb38e41f50b1f..9b11c68ef1a8ba 100644 --- a/docs/api/en/loaders/Loader.html +++ b/docs/api/en/loaders/Loader.html @@ -67,10 +67,11 @@

[method:undefined load]()

This method needs to be implement by all concrete loaders. It holds the logic for loading the asset from the backend.

-

[method:Promise loadAsync]( [param:String url], [param:Function onProgress] )

+

[method:Promise loadAsync]( [param:String url], [param:Function onProgress], [param:AbortSignal abortSignal] )

[page:String url] — A string containing the path/URL of the file to be loaded.
- [page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onProgress] (optional) — A function to be called while the loading is in progress. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

This method is equivalent to [page:.load], but returns a [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise Promise]. diff --git a/docs/api/en/loaders/MaterialLoader.html b/docs/api/en/loaders/MaterialLoader.html index 22eff3945bdd31..168a884092aa76 100644 --- a/docs/api/en/loaders/MaterialLoader.html +++ b/docs/api/en/loaders/MaterialLoader.html @@ -62,13 +62,14 @@

[property:Object textures]

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Material].
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.

+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url.

diff --git a/docs/api/en/loaders/ObjectLoader.html b/docs/api/en/loaders/ObjectLoader.html index 32f8b2269f6513..4d8eaf2b215c84 100644 --- a/docs/api/en/loaders/ObjectLoader.html +++ b/docs/api/en/loaders/ObjectLoader.html @@ -72,13 +72,14 @@

Properties

Methods

See the base [page:Loader] class for common methods.

-

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

+

[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError], [param:AbortSignal abortSignal] )

[page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Object3D object].
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.
+ [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
+ [page:Function onError] (optional) — Will be called when load errors.
+ [page:AbortSignal abortSignal] (optional) — the signal of an AbortController used to cancel the request.

Begin loading from url and call onLoad with the parsed response content. diff --git a/docs/api/en/loaders/TextureLoader.html b/docs/api/en/loaders/TextureLoader.html index a6863840b79bfd..4b3b7e5ab3cd03 100644 --- a/docs/api/en/loaders/TextureLoader.html +++ b/docs/api/en/loaders/TextureLoader.html @@ -85,8 +85,8 @@

[method:Texture load]( [param:String url], [param:Function onLoad], [param:F [page:String url] — the path or URL to the file. This can also be a [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].
[page:Function onLoad] — Will be called when load completes. The argument will be the loaded [page:Texture texture].
- [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
- [page:Function onError] — Will be called when load errors.

+ [page:Function onProgress] (optional) — This callback function is currently not supported.
+ [page:Function onError] (optional) — Will be called when load errors.

Begin loading from the given URL and pass the fully loaded [page:Texture texture] to onLoad. The method also returns a new texture object which can directly be used for material creation. If you do it this way, the texture may pop up in your scene once the respective loading process is finished. diff --git a/src/loaders/AnimationLoader.js b/src/loaders/AnimationLoader.js index 661dab954034cd..8c06f8874417a0 100644 --- a/src/loaders/AnimationLoader.js +++ b/src/loaders/AnimationLoader.js @@ -10,7 +10,7 @@ class AnimationLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -40,7 +40,7 @@ class AnimationLoader extends Loader { } - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); } diff --git a/src/loaders/AudioLoader.js b/src/loaders/AudioLoader.js index 857394e4812f71..caa494dd8f6e82 100644 --- a/src/loaders/AudioLoader.js +++ b/src/loaders/AudioLoader.js @@ -10,7 +10,7 @@ class AudioLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -50,7 +50,7 @@ class AudioLoader extends Loader { } - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); } diff --git a/src/loaders/BufferGeometryLoader.js b/src/loaders/BufferGeometryLoader.js index 5e9b19dfacfa48..7232a16aa5fc85 100644 --- a/src/loaders/BufferGeometryLoader.js +++ b/src/loaders/BufferGeometryLoader.js @@ -18,7 +18,7 @@ class BufferGeometryLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -48,7 +48,7 @@ class BufferGeometryLoader extends Loader { } - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); } diff --git a/src/loaders/CompressedTextureLoader.js b/src/loaders/CompressedTextureLoader.js index 02ef233412d314..4157abf853acd9 100644 --- a/src/loaders/CompressedTextureLoader.js +++ b/src/loaders/CompressedTextureLoader.js @@ -17,7 +17,7 @@ class CompressedTextureLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -60,7 +60,7 @@ class CompressedTextureLoader extends Loader { } - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); } @@ -120,7 +120,7 @@ class CompressedTextureLoader extends Loader { if ( onLoad ) onLoad( texture ); - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); } diff --git a/src/loaders/CubeTextureLoader.js b/src/loaders/CubeTextureLoader.js index 2e784a221e8d27..0c58b547d2d07a 100644 --- a/src/loaders/CubeTextureLoader.js +++ b/src/loaders/CubeTextureLoader.js @@ -10,7 +10,7 @@ class CubeTextureLoader extends Loader { } - load( urls, onLoad, onProgress, onError ) { + load( urls, onLoad, onProgress, onError, abortSignal ) { const texture = new CubeTexture(); @@ -36,7 +36,7 @@ class CubeTextureLoader extends Loader { } - }, undefined, onError ); + }, undefined, onError, abortSignal ); } diff --git a/src/loaders/DataTextureLoader.js b/src/loaders/DataTextureLoader.js index e584dbb9412ac8..90d5c104015229 100644 --- a/src/loaders/DataTextureLoader.js +++ b/src/loaders/DataTextureLoader.js @@ -17,7 +17,7 @@ class DataTextureLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -101,7 +101,7 @@ class DataTextureLoader extends Loader { if ( onLoad ) onLoad( texture, texData ); - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); return texture; diff --git a/src/loaders/FileLoader.js b/src/loaders/FileLoader.js index b42e55bc752ebf..4d02f89deb8f08 100644 --- a/src/loaders/FileLoader.js +++ b/src/loaders/FileLoader.js @@ -11,7 +11,7 @@ class FileLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { if ( url === undefined ) url = ''; @@ -66,11 +66,12 @@ class FileLoader extends Loader { const req = new Request( url, { headers: new Headers( this.requestHeader ), credentials: this.withCredentials ? 'include' : 'same-origin', - // An abort controller could be added within a future PR } ); // start the fetch - fetch( req ) + fetch( req, { + signal: abortSignal, + } ) .then( response => { if ( response.status === 200 || response.status === 0 ) { diff --git a/src/loaders/ImageBitmapLoader.js b/src/loaders/ImageBitmapLoader.js index 2a9d15a3742840..4fbe0e76f30872 100644 --- a/src/loaders/ImageBitmapLoader.js +++ b/src/loaders/ImageBitmapLoader.js @@ -31,7 +31,7 @@ class ImageBitmapLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { if ( url === undefined ) url = ''; @@ -62,6 +62,7 @@ class ImageBitmapLoader extends Loader { const fetchOptions = {}; fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include'; fetchOptions.headers = this.requestHeader; + fetchOptions.signal = abortSignal; fetch( url, fetchOptions ).then( function ( res ) { diff --git a/src/loaders/Loader.js b/src/loaders/Loader.js index 3d161b5d6f62b5..424ee5db716f98 100644 --- a/src/loaders/Loader.js +++ b/src/loaders/Loader.js @@ -14,15 +14,15 @@ class Loader { } - load( /* url, onLoad, onProgress, onError */ ) {} + load( /* url, onLoad, onProgress, onError, abortSignal */ ) {} - loadAsync( url, onProgress ) { + loadAsync( url, onProgress, abortSignal ) { const scope = this; return new Promise( function ( resolve, reject ) { - scope.load( url, resolve, onProgress, reject ); + scope.load( url, resolve, onProgress, reject, abortSignal ); } ); diff --git a/src/loaders/MaterialLoader.js b/src/loaders/MaterialLoader.js index 07df2da7764181..9c7faeb62ce948 100644 --- a/src/loaders/MaterialLoader.js +++ b/src/loaders/MaterialLoader.js @@ -17,7 +17,7 @@ class MaterialLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -47,7 +47,7 @@ class MaterialLoader extends Loader { } - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); } diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index f263ad885f10b1..9e5ec433d132be 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -68,7 +68,7 @@ class ObjectLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, abortSignal ) { const scope = this; @@ -108,7 +108,7 @@ class ObjectLoader extends Loader { scope.parse( json, onLoad ); - }, onProgress, onError ); + }, onProgress, onError, abortSignal ); }