Skip to content

Commit d99be51

Browse files
authored
Merge pull request #13816 from WestLangley/dev-mtl_obj
OBJ/MTL Loaders and Example: add support for chaining
2 parents dd1d166 + 53838a2 commit d99be51

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

examples/js/loaders/MTLLoader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ THREE.MTLLoader.prototype = {
4747
*
4848
* @see setTexturePath
4949
* @param {String} path
50+
* @return {THREE.MTLLoader}
5051
*
5152
* @example
5253
* mtlLoader.setPath( 'assets/obj/' );
@@ -55,6 +56,7 @@ THREE.MTLLoader.prototype = {
5556
setPath: function ( path ) {
5657

5758
this.path = path;
59+
return this;
5860

5961
},
6062

@@ -65,6 +67,7 @@ THREE.MTLLoader.prototype = {
6567
*
6668
* @see setPath
6769
* @param {String} path
70+
* @return {THREE.MTLLoader}
6871
*
6972
* @example
7073
* mtlLoader.setPath( 'assets/obj/' );
@@ -74,26 +77,29 @@ THREE.MTLLoader.prototype = {
7477
setTexturePath: function ( path ) {
7578

7679
this.texturePath = path;
80+
return this;
7781

7882
},
7983

8084
setBaseUrl: function ( path ) {
8185

8286
console.warn( 'THREE.MTLLoader: .setBaseUrl() is deprecated. Use .setTexturePath( path ) for texture path or .setPath( path ) for general base path instead.' );
8387

84-
this.setTexturePath( path );
88+
return this.setTexturePath( path );
8589

8690
},
8791

8892
setCrossOrigin: function ( value ) {
8993

9094
this.crossOrigin = value;
95+
return this;
9196

9297
},
9398

9499
setMaterialOptions: function ( value ) {
95100

96101
this.materialOptions = value;
102+
return this;
97103

98104
},
99105

examples/js/loaders/OBJLoader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ THREE.OBJLoader = ( function () {
392392

393393
this.path = value;
394394

395+
return this;
396+
395397
},
396398

397399
setMaterials: function ( materials ) {

examples/webgl_loader_obj_mtl.html

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,37 @@
7777
// model
7878

7979
var onProgress = function ( xhr ) {
80+
8081
if ( xhr.lengthComputable ) {
82+
8183
var percentComplete = xhr.loaded / xhr.total * 100;
82-
console.log( Math.round(percentComplete, 2) + '% downloaded' );
84+
console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
85+
8386
}
87+
8488
};
8589

8690
var onError = function ( xhr ) { };
8791

8892
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
8993

90-
var mtlLoader = new THREE.MTLLoader();
91-
mtlLoader.setPath( 'models/obj/male02/' );
92-
mtlLoader.load( 'male02_dds.mtl', function( materials ) {
94+
new THREE.MTLLoader()
95+
.setPath( 'models/obj/male02/' )
96+
.load( 'male02_dds.mtl', function ( materials ) {
9397

94-
materials.preload();
98+
materials.preload();
9599

96-
var objLoader = new THREE.OBJLoader();
97-
objLoader.setMaterials( materials );
98-
objLoader.setPath( 'models/obj/male02/' );
99-
objLoader.load( 'male02.obj', function ( object ) {
100+
new THREE.OBJLoader()
101+
.setMaterials( materials )
102+
.setPath( 'models/obj/male02/' )
103+
.load( 'male02.obj', function ( object ) {
100104

101-
object.position.y = - 95;
102-
scene.add( object );
105+
object.position.y = - 95;
106+
scene.add( object );
103107

104-
}, onProgress, onError );
108+
}, onProgress, onError );
105109

106-
});
110+
} );
107111

108112
//
109113

0 commit comments

Comments
 (0)