Skip to content

Commit

Permalink
Merge pull request #17434 from Mugen87/dev38
Browse files Browse the repository at this point in the history
Loader: Remove Handlers.
  • Loading branch information
mrdoob authored Sep 6, 2019
2 parents 87c5fcf + 2aeee4d commit 1536454
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 165 deletions.
25 changes: 0 additions & 25 deletions docs/api/en/loaders/Loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,6 @@ <h3>[method:Loader setResourcePath]( [param:String resourcePath] )</h3>
[page:String resourcePath] — Set the base path for dependent resources like textures.
</p>

<h2>Handlers</h2>

<p>
*[name].Handlers* is a special object normally used by other loaders like [page:GLTFLoader] or [page:MTLLoader]. It provides an
API that allows the definition of special mappings: What loaders should be used in order to load specific files. A typical use case
is to overwrite the default loader for textures.<br /><br />

Note: It's only possible to use *[name].Handlers* if the respective loader support the usage.
</p>

<h3>[method:null add]( [param:Object regex], [param:Loader loader] )</h3>
<p>
[page:Object regex] — A regular expression.<br />
[page:Loader loader] — The loader.
<p>
Registers a loader with the given regular expression.
</p>

<h3>[method:null get]( [param:String file] )</h3>
<p>
[page:String file] — The file path.
<p>
Can be used to retrieve the registered loader for the given file path.
</p>

<h2>Source</h2>

<p>
Expand Down
24 changes: 23 additions & 1 deletion docs/api/en/loaders/managers/LoadingManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,36 @@ <h3>[method:null itemEnd]( [param:String url] )</h3>
This should be called by any loader using the manager when the loader ended loading an url.
</p>


<h3>[method:null itemError]( [param:String url] )</h3>
<p>
[page:String url] — the loaded url<br /><br />

This should be called by any loader using the manager when the loader errors loading an url.
</p>

<h3>[method:LoadingManager addHandler]( [param:Object regex], [param:Loader loader] )</h3>
<p>
[page:Object regex] — A regular expression.<br />
[page:Loader loader] — The loader.
<p>
Registers a loader with the given regular expression. Can be used to define what loader should be used in
order to load specific files. A typical use case is to overwrite the default loader for textures.
</p>

<h3>[method:LoadingManager removeHandler]( [param:Object regex] )</h3>
<p>
[page:Object regex] — A regular expression.
<p>
Removes the loader for the given regular expression.
</p>

<h3>[method:null getHandler]( [param:String file] )</h3>
<p>
[page:String file] — The file path.
<p>
Can be used to retrieve the registered loader for the given file path.
</p>

<h2>Source</h2>

[link:https://github.com/mrdoob/three.js/blob/master/src/loaders/LoadingManager.js src/loaders/LoadingManager.js]
Expand Down
25 changes: 0 additions & 25 deletions docs/api/zh/loaders/Loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,6 @@ <h3>[method:Loader setResourcePath]( [param:String resourcePath] )</h3>
[page:String resourcePath] — Set the base path for dependent resources like textures.
</p>

<h2>Handlers</h2>

<p>
*[name].Handlers* is a special object normally used by other loaders like [page:GLTFLoader] or [page:MTLLoader]. It provides an
API that allows the definition of special mappings: What loaders should be used in order to load specific files. A typical use case
is to overwrite the default loader for textures.<br /><br />

Note: It's only possible to use *[name].Handlers* if the respective loader support the usage.
</p>

<h3>[method:null add]( [param:Object regex], [param:Loader loader] )</h3>
<p>
[page:Object regex] — A regular expression.<br />
[page:Loader loader] — The loader.
<p>
Registers a loader with the given regular expression.
</p>

<h3>[method:null get]( [param:String file] )</h3>
<p>
[page:String file] — The file path.
<p>
Can be used to retrieve the registered loader for the given file path.
</p>

<h2>Source</h2>

<p>
Expand Down
23 changes: 23 additions & 0 deletions docs/api/zh/loaders/managers/LoadingManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,29 @@ <h3>[method:null itemError]( [param:String url] )</h3>
任何使用管理器的加载器都会调用此方法, 当加载器出现加载错误时。
</p>

<h3>[method:LoadingManager addHandler]( [param:Object regex], [param:Loader loader] )</h3>
<p>
[page:Object regex] — A regular expression.<br />
[page:Loader loader] — The loader.
<p>
Registers a loader with the given regular expression. Can be used to define what loader should be used in
order to load specific files. A typical use case is to overwrite the default loader for textures.
</p>

<h3>[method:LoadingManager removeHandler]( [param:Object regex] )</h3>
<p>
[page:Object regex] — A regular expression.
<p>
Removes the loader for the given regular expression.
</p>

<h3>[method:null getHandler]( [param:String file] )</h3>
<p>
[page:String file] — The file path.
<p>
Can be used to retrieve the registered loader for the given file path.
</p>

<h2></h2>

[link:https://github.com/mrdoob/three.js/blob/master/src/loaders/LoadingManager.js src/loaders/LoadingManager.js]
Expand Down
9 changes: 5 additions & 4 deletions examples/js/loaders/FBXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,17 @@ THREE.FBXLoader = ( function () {

var textureLoader = new THREE.TextureLoader( this.manager ).setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );

return new FBXTreeParser( textureLoader ).parse( fbxTree );
return new FBXTreeParser( textureLoader, this.manager ).parse( fbxTree );

}

} );

// Parse the FBXTree object returned by the BinaryParser or TextParser and return a THREE.Group
function FBXTreeParser( textureLoader ) {
function FBXTreeParser( textureLoader, manager ) {

this.textureLoader = textureLoader;
this.manager = manager;

}

Expand Down Expand Up @@ -265,7 +266,7 @@ THREE.FBXLoader = ( function () {

case 'tga':

if ( THREE.Loader.Handlers.get( '.tga' ) === null ) {
if ( this.manager.getHandler( '.tga' ) === null ) {

console.warn( 'FBXLoader: TGA loader not found, skipping ', fileName );

Expand Down Expand Up @@ -378,7 +379,7 @@ THREE.FBXLoader = ( function () {

if ( extension === 'tga' ) {

var loader = THREE.Loader.Handlers.get( '.tga' );
var loader = this.manager.getHandler( '.tga' );

if ( loader === null ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ THREE.GLTFLoader = ( function () {

// Load Texture resource.

var loader = THREE.Loader.Handlers.get( sourceURI );
var loader = options.manager.getHandler( sourceURI );

if ( ! loader ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/MMDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ THREE.MMDLoader = ( function () {

if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];

var loader = THREE.Loader.Handlers.get( fullPath );
var loader = this.manager.getHandler( fullPath );

if ( loader === null ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/MTLLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ THREE.MTLLoader.MaterialCreator.prototype = {
loadTexture: function ( url, mapping, onLoad, onProgress, onError ) {

var texture;
var loader = THREE.Loader.Handlers.get( url );
var manager = ( this.manager !== undefined ) ? this.manager : THREE.DefaultLoadingManager;
var loader = manager.getHandler( url );

if ( loader === null ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/deprecated/LegacyGLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ THREE.LegacyGLTFLoader = ( function () {

}

var textureLoader = THREE.Loader.Handlers.get( sourceUri );
var textureLoader = options.manager.getHandler( sourceUri );

if ( textureLoader === null ) {

Expand Down
32 changes: 16 additions & 16 deletions examples/js/loaders/deprecated/LegacyJSONLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ THREE.LegacyJSONLoader = ( function () {
var _textureLoader = new THREE.TextureLoader();
var _materialLoader = new THREE.MaterialLoader();

function initMaterials( materials, texturePath, crossOrigin ) {
function initMaterials( materials, texturePath, crossOrigin, manager ) {

var array = [];

for ( var i = 0; i < materials.length; ++ i ) {

array[ i ] = createMaterial( materials[ i ], texturePath, crossOrigin );
array[ i ] = createMaterial( materials[ i ], texturePath, crossOrigin, manager );

}

return array;

}

function createMaterial( m, texturePath, crossOrigin ) {
function createMaterial( m, texturePath, crossOrigin, manager ) {

// convert from old material format

Expand Down Expand Up @@ -143,39 +143,39 @@ THREE.LegacyJSONLoader = ( function () {
if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
break;
case 'mapDiffuse':
json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy, textures, texturePath, crossOrigin );
json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapDiffuseRepeat':
case 'mapDiffuseOffset':
case 'mapDiffuseWrap':
case 'mapDiffuseAnisotropy':
break;
case 'mapEmissive':
json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy, textures, texturePath, crossOrigin );
json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapEmissiveRepeat':
case 'mapEmissiveOffset':
case 'mapEmissiveWrap':
case 'mapEmissiveAnisotropy':
break;
case 'mapLight':
json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy, textures, texturePath, crossOrigin );
json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapLightRepeat':
case 'mapLightOffset':
case 'mapLightWrap':
case 'mapLightAnisotropy':
break;
case 'mapAO':
json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy, textures, texturePath, crossOrigin );
json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapAORepeat':
case 'mapAOOffset':
case 'mapAOWrap':
case 'mapAOAnisotropy':
break;
case 'mapBump':
json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy, textures, texturePath, crossOrigin );
json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapBumpScale':
json.bumpScale = value;
Expand All @@ -186,7 +186,7 @@ THREE.LegacyJSONLoader = ( function () {
case 'mapBumpAnisotropy':
break;
case 'mapNormal':
json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy, textures, texturePath, crossOrigin );
json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapNormalFactor':
json.normalScale = value;
Expand All @@ -197,31 +197,31 @@ THREE.LegacyJSONLoader = ( function () {
case 'mapNormalAnisotropy':
break;
case 'mapSpecular':
json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy, textures, texturePath, crossOrigin );
json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapSpecularRepeat':
case 'mapSpecularOffset':
case 'mapSpecularWrap':
case 'mapSpecularAnisotropy':
break;
case 'mapMetalness':
json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy, textures, texturePath, crossOrigin );
json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapMetalnessRepeat':
case 'mapMetalnessOffset':
case 'mapMetalnessWrap':
case 'mapMetalnessAnisotropy':
break;
case 'mapRoughness':
json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy, textures, texturePath, crossOrigin );
json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapRoughnessRepeat':
case 'mapRoughnessOffset':
case 'mapRoughnessWrap':
case 'mapRoughnessAnisotropy':
break;
case 'mapAlpha':
json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy, textures, texturePath, crossOrigin );
json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy, textures, texturePath, crossOrigin, manager );
break;
case 'mapAlphaRepeat':
case 'mapAlphaOffset':
Expand Down Expand Up @@ -271,10 +271,10 @@ THREE.LegacyJSONLoader = ( function () {

}

function loadTexture( path, repeat, offset, wrap, anisotropy, textures, texturePath, crossOrigin ) {
function loadTexture( path, repeat, offset, wrap, anisotropy, textures, texturePath, crossOrigin, manager ) {

var fullPath = texturePath + path;
var loader = THREE.Loader.Handlers.get( fullPath );
var loader = manager.getHandler( fullPath );

var texture;

Expand Down Expand Up @@ -804,7 +804,7 @@ THREE.LegacyJSONLoader = ( function () {

} else {

var materials = initMaterials( json.materials, this.resourcePath || path, this.crossOrigin );
var materials = initMaterials( json.materials, this.resourcePath || path, this.crossOrigin, this.manager );

return { geometry: geometry, materials: materials };

Expand Down
9 changes: 5 additions & 4 deletions examples/jsm/loaders/FBXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,17 @@ var FBXLoader = ( function () {

var textureLoader = new TextureLoader( this.manager ).setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );

return new FBXTreeParser( textureLoader ).parse( fbxTree );
return new FBXTreeParser( textureLoader, this.manager ).parse( fbxTree );

}

} );

// Parse the FBXTree object returned by the BinaryParser or TextParser and return a Group
function FBXTreeParser( textureLoader ) {
function FBXTreeParser( textureLoader, manager ) {

this.textureLoader = textureLoader;
this.manager = manager;

}

Expand Down Expand Up @@ -313,7 +314,7 @@ var FBXLoader = ( function () {

case 'tga':

if ( Loader.Handlers.get( '.tga' ) === null ) {
if ( this.manager.getHandler( '.tga' ) === null ) {

console.warn( 'FBXLoader: TGA loader not found, skipping ', fileName );

Expand Down Expand Up @@ -426,7 +427,7 @@ var FBXLoader = ( function () {

if ( extension === 'tga' ) {

var loader = Loader.Handlers.get( '.tga' );
var loader = this.manager.getHandler( '.tga' );

if ( loader === null ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ var GLTFLoader = ( function () {

// Load Texture resource.

var loader = Loader.Handlers.get( sourceURI );
var loader = options.manager.getHandler( sourceURI );

if ( ! loader ) {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/loaders/MMDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ var MMDLoader = ( function () {

if ( textures[ fullPath ] !== undefined ) return textures[ fullPath ];

var loader = Loader.Handlers.get( fullPath );
var loader = this.manager.getHandler( fullPath );

if ( loader === null ) {

Expand Down
Loading

0 comments on commit 1536454

Please sign in to comment.