|
@@ -22,20 +22,22 @@ THREE.MTLLoader.prototype = {
|
|
|
* @param {Function} [onProgress] - Callback for download progress.
|
|
|
* @param {Function} [onError] - Callback for download errors.
|
|
|
*
|
|
|
- * @see setPath setTexturePath
|
|
|
+ * @see setPath setResourcePath
|
|
|
*
|
|
|
* @note In order for relative texture references to resolve correctly
|
|
|
- * you must call setPath and/or setTexturePath explicitly prior to load.
|
|
|
+ * you must call setResourcePath() explicitly prior to load.
|
|
|
*/
|
|
|
load: function ( url, onLoad, onProgress, onError ) {
|
|
|
|
|
|
var scope = this;
|
|
|
|
|
|
+ var path = ( this.path === undefined ) ? THREE.LoaderUtils.extractUrlBase( url ) : this.path;
|
|
|
+
|
|
|
var loader = new THREE.FileLoader( this.manager );
|
|
|
loader.setPath( this.path );
|
|
|
loader.load( url, function ( text ) {
|
|
|
|
|
|
- onLoad( scope.parse( text ) );
|
|
|
+ onLoad( scope.parse( text, path ) );
|
|
|
|
|
|
}, onProgress, onError );
|
|
|
|
|
@@ -45,7 +47,7 @@ THREE.MTLLoader.prototype = {
|
|
|
* Set base path for resolving references.
|
|
|
* If set this path will be prepended to each loaded and found reference.
|
|
|
*
|
|
|
- * @see setTexturePath
|
|
|
+ * @see setResourcePath
|
|
|
* @param {String} path
|
|
|
* @return {THREE.MTLLoader}
|
|
|
*
|
|
@@ -61,9 +63,7 @@ THREE.MTLLoader.prototype = {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 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.
|
|
|
+ * Set base path for additional resources like textures.
|
|
|
*
|
|
|
* @see setPath
|
|
|
* @param {String} path
|
|
@@ -71,21 +71,20 @@ THREE.MTLLoader.prototype = {
|
|
|
*
|
|
|
* @example
|
|
|
* mtlLoader.setPath( 'assets/obj/' );
|
|
|
- * mtlLoader.setTexturePath( 'assets/textures/' );
|
|
|
+ * mtlLoader.setResourcePath( 'assets/textures/' );
|
|
|
* mtlLoader.load( 'my.mtl', ... );
|
|
|
*/
|
|
|
- setTexturePath: function ( path ) {
|
|
|
+ setResourcePath: function ( path ) {
|
|
|
|
|
|
- this.texturePath = path;
|
|
|
+ this.resourcePath = path;
|
|
|
return this;
|
|
|
|
|
|
},
|
|
|
|
|
|
- setBaseUrl: function ( path ) {
|
|
|
-
|
|
|
- console.warn( 'THREE.MTLLoader: .setBaseUrl() is deprecated. Use .setTexturePath( path ) for texture path or .setPath( path ) for general base path instead.' );
|
|
|
+ setTexturePath: function ( path ) {
|
|
|
|
|
|
- return this.setTexturePath( path );
|
|
|
+ console.warn( 'THREE.MTLLoader: .setTexturePath() has been renamed to .setResourcePath().' );
|
|
|
+ return this.setResourcePath( path );
|
|
|
|
|
|
},
|
|
|
|
|
@@ -109,12 +108,12 @@ THREE.MTLLoader.prototype = {
|
|
|
* @param {String} text - Content of MTL file
|
|
|
* @return {THREE.MTLLoader.MaterialCreator}
|
|
|
*
|
|
|
- * @see setPath setTexturePath
|
|
|
+ * @see setPath setResourcePath
|
|
|
*
|
|
|
* @note In order for relative texture references to resolve correctly
|
|
|
- * you must call setPath and/or setTexturePath explicitly prior to parse.
|
|
|
+ * you must call setResourcePath() explicitly prior to parse.
|
|
|
*/
|
|
|
- parse: function ( text ) {
|
|
|
+ parse: function ( text, path ) {
|
|
|
|
|
|
var lines = text.split( '\n' );
|
|
|
var info = {};
|
|
@@ -165,7 +164,7 @@ THREE.MTLLoader.prototype = {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var materialCreator = new THREE.MTLLoader.MaterialCreator( this.texturePath || this.path, this.materialOptions );
|
|
|
+ var materialCreator = new THREE.MTLLoader.MaterialCreator( this.resourcePath || path, this.materialOptions );
|
|
|
materialCreator.setCrossOrigin( this.crossOrigin );
|
|
|
materialCreator.setManager( this.manager );
|
|
|
materialCreator.setMaterials( materialsInfo );
|