Просмотр исходного кода

Examples: More usage of setPath() and setResourcePath() in loaders.

Mugen87 6 лет назад
Родитель
Сommit
e12b7a25f2

+ 8 - 0
docs/examples/loaders/BabylonLoader.html

@@ -84,6 +84,14 @@
 		Lights are parsed accordingly.
 		</p>
 
+		<h3>[method:BabylonLoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the file.
+		</p>
+
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/BabylonLoader.js examples/js/loaders/BabylonLoader.js]

+ 8 - 0
docs/examples/loaders/PCDLoader.html

@@ -93,6 +93,14 @@
 		The object is converted to [page:Points] with a [page:BufferGeometry] and a [page:PointsMaterial].
 		</p>
 
+		<h3>[method:PCDLoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the file.
+		</p>
+
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/PCDLoader.js examples/js/loaders/PCDLoader.js]

+ 8 - 0
docs/examples/loaders/PDBLoader.html

@@ -87,6 +87,14 @@
 		Parse a <em>pdb</em> text and return a <em>JSON</em> structure.<br />
 		</p>
 
+		<h3>[method:PDBLoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the file.
+		</p>
+
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/PDBLoader.js examples/js/loaders/PDBLoader.js]

+ 8 - 0
docs/examples/loaders/PRWMLoader.html

@@ -94,6 +94,14 @@
 		Return true if the endianness of the platform is Big Endian, false otherwise.
 		</p>
 
+		<h3>[method:PRWMLoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the file.
+		</p>
+
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/PRWMLoader.js examples/js/loaders/PRWMLoader.js]

+ 7 - 0
docs/examples/loaders/SVGLoader.html

@@ -99,6 +99,13 @@
 		Begin loading from url and call onLoad with the response content.
 		</p>
 
+		<h3>[method:SVGLoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the file.
+		</p>
 
 		<h2>Source</h2>
 

+ 8 - 0
docs/examples/loaders/TGALoader.html

@@ -76,6 +76,14 @@
 		Begin loading from url and pass the loaded [page:DataTexture texture] to onLoad. The [page:DataTexture texture] is also directly returned for immediate use (but may not be fully loaded).
 		</p>
 
+		<h3>[method:TGALoader setPath]( [param:String path] )</h3>
+		<p>
+		[page:String path] — Base path.
+		</p>
+		<p>
+		Set the base path for the file.
+		</p>
+
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/TGALoader.js examples/js/loaders/TGALoader.js]

+ 8 - 0
examples/js/loaders/3MFLoader.js

@@ -17,6 +17,7 @@ THREE.ThreeMFLoader.prototype = {
 
 		var scope = this;
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( buffer ) {
 
@@ -26,6 +27,13 @@ THREE.ThreeMFLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data ) {
 
 		var scope = this;

+ 8 - 0
examples/js/loaders/AMFLoader.js

@@ -33,6 +33,7 @@ THREE.AMFLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( text ) {
 
@@ -42,6 +43,13 @@ THREE.AMFLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data ) {
 
 		function loadDocument( data ) {

+ 8 - 0
examples/js/loaders/AWDLoader.js

@@ -116,6 +116,7 @@
 			this._baseDir = url.substr( 0, url.lastIndexOf( '/' ) + 1 );
 
 			var loader = new THREE.FileLoader( this.manager );
+			loader.setPath( this.path );
 			loader.setResponseType( 'arraybuffer' );
 			loader.load( url, function ( text ) {
 
@@ -125,6 +126,13 @@
 
 		},
 
+		setPath: function ( value ) {
+
+			this.path = value;
+			return this;
+
+		},
+
 		parse: function ( data ) {
 
 			var blen = data.byteLength;

+ 8 - 0
examples/js/loaders/BVHLoader.js

@@ -26,6 +26,7 @@ THREE.BVHLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
 			onLoad( scope.parse( text ) );
@@ -34,6 +35,13 @@ THREE.BVHLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( text ) {
 
 		/*

+ 8 - 0
examples/js/loaders/BabylonLoader.js

@@ -18,6 +18,7 @@ THREE.BabylonLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
 			onLoad( scope.parse( JSON.parse( text ) ) );
@@ -26,6 +27,13 @@ THREE.BabylonLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( json ) {
 
 		function parseMaterials( json ) {

+ 8 - 0
examples/js/loaders/GCodeLoader.js

@@ -23,6 +23,7 @@ THREE.GCodeLoader.prototype.load = function ( url, onLoad, onProgress, onError )
 	var self = this;
 
 	var loader = new THREE.FileLoader( self.manager );
+	loader.setPath( self.path );
 	loader.load( url, function ( text ) {
 
 		onLoad( self.parse( text ) );
@@ -31,6 +32,13 @@ THREE.GCodeLoader.prototype.load = function ( url, onLoad, onProgress, onError )
 
 };
 
+THREE.GCodeLoader.prototype.setPath = function ( value ) {
+
+	this.path = value;
+	return this;
+
+};
+
 THREE.GCodeLoader.prototype.parse = function ( data ) {
 
 	var state = { x: 0, y: 0, z: 0, e: 0, f: 0, extruding: false, relative: false };

+ 8 - 0
examples/js/loaders/HDRCubeTextureLoader.js

@@ -109,6 +109,7 @@ THREE.HDRCubeTextureLoader.prototype.load = function ( type, urls, onLoad, onPro
 	function loadHDRData( i, onLoad, onProgress, onError ) {
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( urls[ i ], function ( buffer ) {
 
@@ -184,3 +185,10 @@ THREE.HDRCubeTextureLoader.prototype.load = function ( type, urls, onLoad, onPro
 	return texture;
 
 };
+
+THREE.HDRCubeTextureLoader.prototype.setPath = function ( value ) {
+
+	this.path = value;
+	return this;
+
+};

+ 8 - 0
examples/js/loaders/KMZLoader.js

@@ -17,6 +17,7 @@ THREE.KMZLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( text ) {
 
@@ -26,6 +27,13 @@ THREE.KMZLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data ) {
 
 		function findFile( url ) {

+ 8 - 0
examples/js/loaders/MD2Loader.js

@@ -17,6 +17,7 @@ THREE.MD2Loader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( buffer ) {
 
@@ -26,6 +27,13 @@ THREE.MD2Loader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: ( function () {
 
 		var normalData = [

+ 8 - 0
examples/js/loaders/NRRDLoader.js

@@ -14,6 +14,7 @@ THREE.NRRDLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( data ) {
 
@@ -23,6 +24,13 @@ THREE.NRRDLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data ) {
 
 		// this parser is largely inspired from the XTK NRRD parser : https://github.com/xtk/X

+ 42 - 34
examples/js/loaders/NodeMaterialLoader.js

@@ -73,6 +73,7 @@ Object.assign( THREE.NodeMaterialLoader.prototype, {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
 			onLoad( scope.parse( JSON.parse( text ) ) );
@@ -83,6 +84,13 @@ Object.assign( THREE.NodeMaterialLoader.prototype, {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	getObjectByName: function ( uuid ) {
 
 		return this.names[ uuid ];
@@ -91,10 +99,10 @@ Object.assign( THREE.NodeMaterialLoader.prototype, {
 
 	getObjectById: function ( uuid ) {
 
-		return this.library[ uuid ] || 
-			this.nodes[ uuid ] || 
+		return this.library[ uuid ] ||
+			this.nodes[ uuid ] ||
 			this.materials[ uuid ] ||
-			this.passes[ uuid ] || 
+			this.passes[ uuid ] ||
 			this.names[ uuid ];
 
 	},
@@ -114,54 +122,54 @@ Object.assign( THREE.NodeMaterialLoader.prototype, {
 	},
 
 	resolve: function( json ) {
-		
+
 		switch( typeof json ) {
-			
+
 			case "boolean":
 			case "number":
-			
+
 				return json;
-			
+
 			case "string":
-			
+
 				if (/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i.test(json) || this.library[ json ]) {
-					
+
 					return this.getNode( json );
-					
+
 				}
-				
+
 				return json;
 
 			default:
-			
+
 				if ( Array.isArray( json ) ) {
-			
+
 					for(var i = 0; i < json.length; i++) {
-						
+
 						json[i] = this.resolve( json[i] );
-						
+
 					}
-					
+
 				} else {
-					
+
 					for ( var prop in json ) {
-						
+
 						if (prop === "uuid") continue;
-						
+
 						json[ prop ] = this.resolve( json[ prop ] );
-						
+
 					}
-					
+
 				}
-				
+
 		}
-		
+
 		return json;
-		
+
 	},
-	
+
 	declare: function( json ) {
-		
+
 		var uuid, node, object;
 
 		for ( uuid in json.nodes ) {
@@ -219,31 +227,31 @@ Object.assign( THREE.NodeMaterialLoader.prototype, {
 		}
 
 		if ( json.material ) this.material = this.materials[ json.material ];
-		
+
 		if ( json.pass ) this.pass = this.passes[ json.pass ];
-		
+
 		return json;
-		
+
 	},
-	
+
 	parse: function ( json ) {
 
 		var uuid;
-	
+
 		json = this.resolve( this.declare( json ) );
-		
+
 		for ( uuid in json.nodes ) {
 
 			this.nodes[ uuid ].copy( json.nodes[ uuid ] );
 
 		}
-		
+
 		for ( uuid in json.materials ) {
 
 			this.materials[ uuid ].copy( json.materials[ uuid ] );
 
 		}
-		
+
 		for ( uuid in json.passes ) {
 
 			this.passes[ uuid ].copy( json.passes[ uuid ] );

+ 8 - 0
examples/js/loaders/PCDLoader.js

@@ -25,6 +25,7 @@ THREE.PCDLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( data ) {
 
@@ -50,6 +51,13 @@ THREE.PCDLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data, url ) {
 
 		function parseHeader( data ) {

+ 8 - 0
examples/js/loaders/PDBLoader.js

@@ -18,6 +18,7 @@ THREE.PDBLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
 			onLoad( scope.parse( text ) );
@@ -26,6 +27,13 @@ THREE.PDBLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	// Based on CanvasMol PDB parser
 
 	parse: function ( text ) {

+ 8 - 0
examples/js/loaders/PLYLoader.js

@@ -44,6 +44,7 @@ THREE.PLYLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( this.manager );
+		loader.setPath( this.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( text ) {
 
@@ -53,6 +54,13 @@ THREE.PLYLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	setPropertyNameMapping: function ( mapping ) {
 
 		this.propertyNameMapping = mapping;

+ 8 - 0
examples/js/loaders/PRWMLoader.js

@@ -239,6 +239,7 @@
 			var scope = this;
 
 			var loader = new THREE.FileLoader( scope.manager );
+			loader.setPath( scope.path );
 			loader.setResponseType( 'arraybuffer' );
 
 			url = url.replace( /\*/g, isBigEndianPlatform() ? 'be' : 'le' );
@@ -251,6 +252,13 @@
 
 		},
 
+		setPath: function ( value ) {
+
+			this.path = value;
+			return this;
+
+		},
+
 		parse: function ( arrayBuffer ) {
 
 			console.time( 'PRWMLoader' );

+ 8 - 0
examples/js/loaders/PlayCanvasLoader.js

@@ -18,6 +18,7 @@ THREE.PlayCanvasLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
 			onLoad( scope.parse( JSON.parse( text ) ) );
@@ -26,6 +27,13 @@ THREE.PlayCanvasLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( json ) {
 
 		function parseVertices( data ) {

+ 8 - 0
examples/js/loaders/STLLoader.js

@@ -45,6 +45,7 @@ THREE.STLLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( text ) {
 
@@ -66,6 +67,13 @@ THREE.STLLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data ) {
 
 		function isBinary( data ) {

+ 8 - 0
examples/js/loaders/SVGLoader.js

@@ -19,6 +19,7 @@ THREE.SVGLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
 			onLoad( scope.parse( text ) );
@@ -27,6 +28,13 @@ THREE.SVGLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( text ) {
 
 		function parseNode( node, style ) {

+ 8 - 0
examples/js/loaders/TTFLoader.js

@@ -23,6 +23,7 @@ THREE.TTFLoader.prototype = {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( this.manager );
+		loader.setPath( this.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( buffer ) {
 
@@ -32,6 +33,13 @@ THREE.TTFLoader.prototype = {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( arraybuffer ) {
 
 		function convert( font, reversed ) {

+ 30 - 14
examples/js/loaders/VRMLLoader.js

@@ -32,15 +32,32 @@ THREE.VRMLLoader.prototype = {
 
 		var scope = this;
 
+		var path = ( scope.path === undefined ) ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
+
 		var loader = new THREE.FileLoader( this.manager );
+		loader.setPath( scope.path );
 		loader.load( url, function ( text ) {
 
-			onLoad( scope.parse( text ) );
+			onLoad( scope.parse( text, path ) );
 
 		}, onProgress, onError );
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
+	setResourcePath: function ( value ) {
+
+		this.resourcePath = value;
+		return this;
+
+	},
+
 	setCrossOrigin: function ( value ) {
 
 		this.crossOrigin = value;
@@ -48,13 +65,12 @@ THREE.VRMLLoader.prototype = {
 
 	},
 
-	parse: function ( data ) {
+	parse: function ( data, path ) {
 
 		var scope = this;
-		var texturePath = this.texturePath || '';
 
 		var textureLoader = new THREE.TextureLoader( this.manager );
-		textureLoader.setCrossOrigin( this.crossOrigin );
+		textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
 
 		function parseV2( lines, scene ) {
 
@@ -931,23 +947,23 @@ THREE.VRMLLoader.prototype = {
 								for ( i = 0, il = indexArray.length; i < il; i ++ ) {
 
 									var indexedFace = indexArray[ i ];
-	
+
 									// VRML support multipoint indexed face sets (more then 3 vertices). You must calculate the composing triangles here
-	
+
 									skip = 0;
-	
+
 									while ( indexedFace.length >= 3 && skip < ( indexedFace.length - 2 ) ) {
 
 										var i1 = indexedFace[ 0 ];
 										var i2 = indexedFace[ skip + ( ccw ? 1 : 2 ) ];
 										var i3 = indexedFace[ skip + ( ccw ? 2 : 1 ) ];
-	
+
 										triangulatedIndexArray.push( i1, i2, i3 );
-	
+
 										skip ++;
-	
+
 									}
-	
+
 								}
 
 								return triangulatedIndexArray;
@@ -988,7 +1004,7 @@ THREE.VRMLLoader.prototype = {
 
 								}
 
-								if ( colorIndex !== undefined ) { 
+								if ( colorIndex !== undefined ) {
 
 									pointAttributes.push( colorIndex.toString( base ) );
 
@@ -1093,7 +1109,7 @@ THREE.VRMLLoader.prototype = {
 
 						} else {
 
-							// convert geometry to non-indexed to get sharp normals 
+							// convert geometry to non-indexed to get sharp normals
 							geometry = geometry.toNonIndexed();
 							geometry.computeVertexNormals();
 
@@ -1180,7 +1196,7 @@ THREE.VRMLLoader.prototype = {
 
 								parent.material.name = textureName[ 1 ];
 
-								parent.material.map = textureLoader.load( texturePath + textureName[ 1 ] );
+								parent.material.map = textureLoader.load( textureName[ 1 ] );
 
 							}
 

+ 8 - 0
examples/js/loaders/VTKLoader.js

@@ -22,6 +22,7 @@ Object.assign( THREE.VTKLoader.prototype, THREE.EventDispatcher.prototype, {
 		var scope = this;
 
 		var loader = new THREE.FileLoader( scope.manager );
+		loader.setPath( scope.path );
 		loader.setResponseType( 'arraybuffer' );
 		loader.load( url, function ( text ) {
 
@@ -31,6 +32,13 @@ Object.assign( THREE.VTKLoader.prototype, THREE.EventDispatcher.prototype, {
 
 	},
 
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
 	parse: function ( data ) {
 
 		function parseASCII( data ) {