提交 8711dac3 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #11259 from donmccurdy/feat-loading-manager-transforms

[LoadingManager] Support URL transforms. 
......@@ -121,6 +121,25 @@
<h2>Methods</h2>
<h3>[method:null setURLModifier]( [page:Function callback] )</h3>
<div>
[page:Function callback] — URL modifier callback. Called with [page:String url] argument, and
must return [page:String resolvedURL].<br /><br />
If provided, the callback will be passed each resource URL before a request is sent. The
callback may return the original URL, or a new URL to override loading behavior. This
behavior can be used to load assets from .ZIP files, drag-and-drop APIs, and Data URIs.
</div>
<h3>[method:String resolveURL]( [page:String url] )</h3>
<div>
[page:String url] — the url to load<br /><br />
Given a URL, uses the URL modifier callback (if any) and returns a resolved URL. If no
URL modifier is set, returns the original URL.
</div>
<br /><br />
<div>
<em>Note: The following methods are designed to be called internally by loaders. You shouldn't call
them directly.</em>
......
......@@ -21,6 +21,8 @@ Object.assign( FileLoader.prototype, {
if ( this.path !== undefined ) url = this.path + url;
url = this.manager.resolveURL( url );
var scope = this;
var cached = Cache.get( url );
......
......@@ -22,6 +22,8 @@ Object.assign( ImageLoader.prototype, {
if ( this.path !== undefined ) url = this.path + url;
url = this.manager.resolveURL( url );
var scope = this;
var cached = Cache.get( url );
......
......@@ -6,7 +6,10 @@ function LoadingManager( onLoad, onProgress, onError ) {
var scope = this;
var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
var isLoading = false;
var itemsLoaded = 0;
var itemsTotal = 0;
var urlModifier = undefined;
this.onStart = undefined;
this.onLoad = onLoad;
......@@ -65,6 +68,24 @@ function LoadingManager( onLoad, onProgress, onError ) {
};
this.resolveURL = function ( url ) {
if ( urlModifier ) {
return urlModifier( url );
}
return url;
};
this.setURLModifier = function ( transform ) {
urlModifier = transform;
};
}
var DefaultLoadingManager = new LoadingManager();
......
......@@ -98,7 +98,7 @@ export * from '../src/geometries/Geometries.js';
//src/helpers
export { ArrowHelper } from '../src/helpers/ArrowHelper.js';
export { AxisHelper } from '../src/helpers/AxisHelper.js';
export { AxesHelper } from '../src/helpers/AxesHelper.js';
export { BoxHelper } from '../src/helpers/BoxHelper.js';
export { Box3Helper } from '../src/helpers/Box3Helper.js';
export { CameraHelper } from '../src/helpers/CameraHelper.js';
......
......@@ -3,4 +3,4 @@
*/
//Todo
console.warn("Todo: Unit tests of AxisHelper")
console.warn("Todo: Unit tests of AxesHelper")
/**
* @author TristanVALCKE / https://github.com/TristanVALCKE
* @author Don McCurdy / https://github.com/donmccurdy
*/
//Todo
console.warn("Todo: Unit tests of LoadingManager")
QUnit.module( 'LoadingManager' );
QUnit.test( 'setURLModifier', function( assert ) {
var manager = new THREE.LoadingManager();
var suffix = '?transformed=true';
manager.setURLModifier( function ( url ) {
return url + suffix;
} );
var url = 'https://foo.bar/baz';
var resolvedURL = manager.resolveURL( url );
assert.equal( resolvedURL, url + suffix, 'URL transform is applied' );
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册