Browse Source

Merge pull request #12731 from cnspaha/patch-2

TDSLoader: Fix double 'pathing'
Mr.doob 7 years ago
parent
commit
d70d95ced5
1 changed files with 17 additions and 29 deletions
  1. 17 29
      examples/js/loaders/TDSLoader.js

+ 17 - 29
examples/js/loaders/TDSLoader.js

@@ -22,8 +22,6 @@ THREE.TDSLoader = function ( manager ) {
 	this.materials = [];
 	this.materials = [];
 	this.meshes = [];
 	this.meshes = [];
 
 
-	this.path = "";
-
 };
 };
 
 
 THREE.TDSLoader.prototype = {
 THREE.TDSLoader.prototype = {
@@ -43,22 +41,16 @@ THREE.TDSLoader.prototype = {
 
 
 		var scope = this;
 		var scope = this;
 
 
-		var path = this.path;
-		if ( this.path === "" )	{
-
-			path = THREE.Loader.prototype.extractUrlBase( url );
 
 
-		}
+		var path = this.path !== undefined ? this.path : THREE.Loader.prototype.extractUrlBase( url );
 
 
 		var loader = new THREE.FileLoader( this.manager );
 		var loader = new THREE.FileLoader( this.manager );
 
 
 		loader.setResponseType( 'arraybuffer' );
 		loader.setResponseType( 'arraybuffer' );
 
 
-		loader.setPath( path );
-
 		loader.load( url, function ( data ) {
 		loader.load( url, function ( data ) {
 
 
-			onLoad( scope.parse( data ) );
+			onLoad( scope.parse( data, path ) );
 
 
 		}, onProgress, onError );
 		}, onProgress, onError );
 
 
@@ -72,14 +64,14 @@ THREE.TDSLoader.prototype = {
 	 * @param {String} path Path for external resources.
 	 * @param {String} path Path for external resources.
 	 * @return {Object3D} Group loaded from 3ds file.
 	 * @return {Object3D} Group loaded from 3ds file.
 	 */
 	 */
-	parse: function ( arraybuffer ) {
+	parse: function ( arraybuffer, path ) {
 
 
 		this.group = new THREE.Group();
 		this.group = new THREE.Group();
 		this.position = 0;
 		this.position = 0;
 		this.materials = [];
 		this.materials = [];
 		this.meshes = [];
 		this.meshes = [];
 
 
-		this.readFile( arraybuffer );
+		this.readFile( arraybuffer, path );
 
 
 		for ( var i = 0; i < this.meshes.length; i ++ ) {
 		for ( var i = 0; i < this.meshes.length; i ++ ) {
 
 
@@ -97,7 +89,7 @@ THREE.TDSLoader.prototype = {
 	 * @method readFile
 	 * @method readFile
 	 * @param {ArrayBuffer} arraybuffer Arraybuffer data to be loaded.
 	 * @param {ArrayBuffer} arraybuffer Arraybuffer data to be loaded.
 	 */
 	 */
-	readFile: function ( arraybuffer ) {
+	readFile: function ( arraybuffer, path ) {
 
 
 		var data = new DataView( arraybuffer );
 		var data = new DataView( arraybuffer );
 		var chunk = this.readChunk( data );
 		var chunk = this.readChunk( data );
@@ -116,7 +108,7 @@ THREE.TDSLoader.prototype = {
 				} else if ( next === MDATA ) {
 				} else if ( next === MDATA ) {
 
 
 					this.resetPosition( data );
 					this.resetPosition( data );
-					this.readMeshData( data );
+					this.readMeshData( data, path );
 
 
 				} else {
 				} else {
 
 
@@ -140,7 +132,7 @@ THREE.TDSLoader.prototype = {
 	 * @method readMeshData
 	 * @method readMeshData
 	 * @param {Dataview} data Dataview in use.
 	 * @param {Dataview} data Dataview in use.
 	 */
 	 */
-	readMeshData: function ( data ) {
+	readMeshData: function ( data, path ) {
 
 
 		var chunk = this.readChunk( data );
 		var chunk = this.readChunk( data );
 		var next = this.nextChunk( data, chunk );
 		var next = this.nextChunk( data, chunk );
@@ -168,7 +160,7 @@ THREE.TDSLoader.prototype = {
 
 
 				this.debugMessage( 'Material' );
 				this.debugMessage( 'Material' );
 				this.resetPosition( data );
 				this.resetPosition( data );
-				this.readMaterialEntry( data );
+				this.readMaterialEntry( data, path );
 
 
 			} else {
 			} else {
 
 
@@ -224,7 +216,7 @@ THREE.TDSLoader.prototype = {
 	 * @method readMaterialEntry
 	 * @method readMaterialEntry
 	 * @param {Dataview} data Dataview in use.
 	 * @param {Dataview} data Dataview in use.
 	 */
 	 */
-	readMaterialEntry: function ( data ) {
+	readMaterialEntry: function ( data, path ) {
 
 
 		var chunk = this.readChunk( data );
 		var chunk = this.readChunk( data );
 		var next = this.nextChunk( data, chunk );
 		var next = this.nextChunk( data, chunk );
@@ -283,25 +275,25 @@ THREE.TDSLoader.prototype = {
 
 
 				this.debugMessage( '   ColorMap' );
 				this.debugMessage( '   ColorMap' );
 				this.resetPosition( data );
 				this.resetPosition( data );
-				material.map = this.readMap( data );
+				material.map = this.readMap( data, path );
 
 
 			} else if ( next === MAT_BUMPMAP ) {
 			} else if ( next === MAT_BUMPMAP ) {
 
 
 				this.debugMessage( '   BumpMap' );
 				this.debugMessage( '   BumpMap' );
 				this.resetPosition( data );
 				this.resetPosition( data );
-				material.bumpMap = this.readMap( data );
+				material.bumpMap = this.readMap( data, path );
 
 
 			} else if ( next === MAT_OPACMAP ) {
 			} else if ( next === MAT_OPACMAP ) {
 
 
 				this.debugMessage( '   OpacityMap' );
 				this.debugMessage( '   OpacityMap' );
 				this.resetPosition( data );
 				this.resetPosition( data );
-				material.alphaMap = this.readMap( data );
+				material.alphaMap = this.readMap( data, path );
 
 
 			} else if ( next === MAT_SPECMAP ) {
 			} else if ( next === MAT_SPECMAP ) {
 
 
 				this.debugMessage( '   SpecularMap' );
 				this.debugMessage( '   SpecularMap' );
 				this.resetPosition( data );
 				this.resetPosition( data );
-				material.specularMap = this.readMap( data );
+				material.specularMap = this.readMap( data, path );
 
 
 			} else {
 			} else {
 
 
@@ -570,14 +562,14 @@ THREE.TDSLoader.prototype = {
 	 * @param {Dataview} data Dataview in use.
 	 * @param {Dataview} data Dataview in use.
 	 * @return {Texture} Texture read from this data chunk.
 	 * @return {Texture} Texture read from this data chunk.
 	 */
 	 */
-	readMap: function ( data ) {
+	readMap: function ( data, path ) {
 
 
 		var chunk = this.readChunk( data );
 		var chunk = this.readChunk( data );
 		var next = this.nextChunk( data, chunk );
 		var next = this.nextChunk( data, chunk );
 		var texture = {};
 		var texture = {};
 
 
 		var loader = new THREE.TextureLoader( this.manager );
 		var loader = new THREE.TextureLoader( this.manager );
-		loader.setPath( this.path );
+		loader.setPath( path );
 
 
 		while ( next !== 0 ) {
 		while ( next !== 0 ) {
 
 
@@ -586,7 +578,7 @@ THREE.TDSLoader.prototype = {
 				var name = this.readString( data, 128 );
 				var name = this.readString( data, 128 );
 				texture = loader.load( name );
 				texture = loader.load( name );
 
 
-				this.debugMessage( '      File: ' + this.path + name );
+				this.debugMessage( '      File: ' + path + name );
 
 
 			} else if ( next === MAT_MAP_UOFFSET ) {
 			} else if ( next === MAT_MAP_UOFFSET ) {
 
 
@@ -907,11 +899,7 @@ THREE.TDSLoader.prototype = {
 	 */
 	 */
 	setPath: function ( path ) {
 	setPath: function ( path ) {
 
 
-		if ( path !== undefined ) {
-
-			this.path = path;
-
-		}
+		this.path = path;
 
 
 		return this;
 		return this;