Skip to content

Commit 05e0eed

Browse files
authored
Merge pull request #14971 from Mugen87/dev9
MTLLoader: Introduced new path handling.
2 parents 7d2a363 + 6a2e54e commit 05e0eed

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

docs/examples/loaders/MTLLoader.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ <h3>[method:MTLLoader setPath]( [param:String path] )</h3>
4949
[page:String path] — required<br />
5050
</p>
5151
<p>
52-
Set base path for resolving references. If set this path will be prepended to each loaded and found reference.
52+
Set base path for MTL file.
5353
</p>
5454

5555

56-
<h3>[method:MTLLoader setTexturePath]( [param:String path] )</h3>
56+
<h3>[method:MTLLoader setResourcePath]( [param:String path] )</h3>
5757
<p>
5858
[page:String path] — required<br />
5959
</p>
6060
<p>
61-
Set base path for resolving texture references. If set this path will be prepended found texture reference. If not set and setPath is, it will be used as texture base path.
61+
Set base path for additional resources like textures. If set, this path will be used as the base path.
6262
</p>
6363

6464

@@ -88,9 +88,10 @@ <h3>[method:MTLLoader setMaterialOptions]( [param:Object options] )</h3>
8888
</p>
8989

9090

91-
<h3>[method:MTLLoaderMaterialCreator parse]( [param:String text] )</h3>
91+
<h3>[method:MTLLoaderMaterialCreator parse]( [param:String text, param:String path] )</h3>
9292
<p>
9393
[page:String text] — The textual <em>mtl</em> structure to parse.
94+
[page:String path] — The path to the MTL file.
9495
</p>
9596
<p>
9697
Parse a <em>mtl</em> text structure and return a [page:MTLLoaderMaterialCreator] instance.<br />

examples/js/loaders/MTLLoader.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ THREE.MTLLoader.prototype = {
2222
* @param {Function} [onProgress] - Callback for download progress.
2323
* @param {Function} [onError] - Callback for download errors.
2424
*
25-
* @see setPath setTexturePath
25+
* @see setPath setResourcePath
2626
*
2727
* @note In order for relative texture references to resolve correctly
28-
* you must call setPath and/or setTexturePath explicitly prior to load.
28+
* you must call setResourcePath() explicitly prior to load.
2929
*/
3030
load: function ( url, onLoad, onProgress, onError ) {
3131

3232
var scope = this;
3333

34+
var path = ( this.path === undefined ) ? THREE.LoaderUtils.extractUrlBase( url ) : this.path;
35+
3436
var loader = new THREE.FileLoader( this.manager );
3537
loader.setPath( this.path );
3638
loader.load( url, function ( text ) {
3739

38-
onLoad( scope.parse( text ) );
40+
onLoad( scope.parse( text, path ) );
3941

4042
}, onProgress, onError );
4143

@@ -45,7 +47,7 @@ THREE.MTLLoader.prototype = {
4547
* Set base path for resolving references.
4648
* If set this path will be prepended to each loaded and found reference.
4749
*
48-
* @see setTexturePath
50+
* @see setResourcePath
4951
* @param {String} path
5052
* @return {THREE.MTLLoader}
5153
*
@@ -61,31 +63,28 @@ THREE.MTLLoader.prototype = {
6163
},
6264

6365
/**
64-
* Set base path for resolving texture references.
65-
* If set this path will be prepended found texture reference.
66-
* If not set and setPath is, it will be used as texture base path.
66+
* Set base path for additional resources like textures.
6767
*
6868
* @see setPath
6969
* @param {String} path
7070
* @return {THREE.MTLLoader}
7171
*
7272
* @example
7373
* mtlLoader.setPath( 'assets/obj/' );
74-
* mtlLoader.setTexturePath( 'assets/textures/' );
74+
* mtlLoader.setResourcePath( 'assets/textures/' );
7575
* mtlLoader.load( 'my.mtl', ... );
7676
*/
77-
setTexturePath: function ( path ) {
77+
setResourcePath: function ( path ) {
7878

79-
this.texturePath = path;
79+
this.resourcePath = path;
8080
return this;
8181

8282
},
8383

84-
setBaseUrl: function ( path ) {
85-
86-
console.warn( 'THREE.MTLLoader: .setBaseUrl() is deprecated. Use .setTexturePath( path ) for texture path or .setPath( path ) for general base path instead.' );
84+
setTexturePath: function ( path ) {
8785

88-
return this.setTexturePath( path );
86+
console.warn( 'THREE.MTLLoader: .setTexturePath() has been renamed to .setResourcePath().' );
87+
return this.setResourcePath( path );
8988

9089
},
9190

@@ -109,12 +108,12 @@ THREE.MTLLoader.prototype = {
109108
* @param {String} text - Content of MTL file
110109
* @return {THREE.MTLLoader.MaterialCreator}
111110
*
112-
* @see setPath setTexturePath
111+
* @see setPath setResourcePath
113112
*
114113
* @note In order for relative texture references to resolve correctly
115-
* you must call setPath and/or setTexturePath explicitly prior to parse.
114+
* you must call setResourcePath() explicitly prior to parse.
116115
*/
117-
parse: function ( text ) {
116+
parse: function ( text, path ) {
118117

119118
var lines = text.split( '\n' );
120119
var info = {};
@@ -165,7 +164,7 @@ THREE.MTLLoader.prototype = {
165164

166165
}
167166

168-
var materialCreator = new THREE.MTLLoader.MaterialCreator( this.texturePath || this.path, this.materialOptions );
167+
var materialCreator = new THREE.MTLLoader.MaterialCreator( this.resourcePath || path, this.materialOptions );
169168
materialCreator.setCrossOrigin( this.crossOrigin );
170169
materialCreator.setManager( this.manager );
171170
materialCreator.setMaterials( materialsInfo );

examples/js/loaders/OBJLoader2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ THREE.OBJLoader2 = (function () {
13971397
var mtlLoader = new THREE.MTLLoader( this.manager );
13981398
crossOrigin = Validator.verifyInput( crossOrigin, 'anonymous' );
13991399
mtlLoader.setCrossOrigin( crossOrigin );
1400-
mtlLoader.setPath( resource.path );
1400+
mtlLoader.setResourcePath( resource.path );
14011401
if ( Validator.isValid( materialOptions ) ) mtlLoader.setMaterialOptions( materialOptions );
14021402

14031403
var parseTextWithMtlLoader = function ( content ) {

0 commit comments

Comments
 (0)