Browse Source

ObjectLoader: Added setPath(), setTexturePath() -> setResourcePath().

Mugen87 6 years ago
parent
commit
963bcc8144
4 changed files with 39 additions and 18 deletions
  1. 8 5
      docs/api/en/loaders/ObjectLoader.html
  2. 1 1
      editor/js/Loader.js
  3. 12 0
      src/Three.Legacy.js
  4. 18 12
      src/loaders/ObjectLoader.js

+ 8 - 5
docs/api/en/loaders/ObjectLoader.html

@@ -85,9 +85,9 @@
 			The [page:LoadingManager loadingManager]  the loader is using. Default is [page:DefaultLoadingManager].
 			The [page:LoadingManager loadingManager]  the loader is using. Default is [page:DefaultLoadingManager].
 		</p>
 		</p>
 
 
-		<h3>[property:String texturePath]</h3>
+		<h3>[property:String resourcePath]</h3>
 		<p>
 		<p>
-			The base path or URL from which textures will be loaded. See [page:.setTexturePath].
+			The base path or URL from which additional resources like textuures will be loaded. See [page:.setResourcePath].
 			Default is the empty string.
 			Default is the empty string.
 		</p>
 		</p>
 
 
@@ -217,11 +217,14 @@
 		[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
 		[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
 		</p>
 		</p>
 
 
-		<h3>[method:ObjectLoader setTexturePath]( [param:String value] )</h3>
+		<h3>[method:ObjectLoader setPath]( [param:String value] )</h3>
 		<p>
 		<p>
-		[page:String value] — The base path or URL from which textures will be loaded.<br /><br />
-
+			Set the base path for the original file.
+		</p>
 
 
+		<h3>[method:ObjectLoader setResourcePath]( [param:String value] )</h3>
+		<p>
+			Set the base path for dependent resources like textures.
 		</p>
 		</p>
 
 
 		<h2>Source</h2>
 		<h2>Source</h2>

+ 1 - 1
editor/js/Loader.js

@@ -626,7 +626,7 @@ var Loader = function ( editor ) {
 			case 'object':
 			case 'object':
 
 
 				var loader = new THREE.ObjectLoader();
 				var loader = new THREE.ObjectLoader();
-				loader.setTexturePath( scope.texturePath );
+				loader.setResourcePath( scope.texturePath );
 
 
 				var result = loader.parse( data );
 				var result = loader.parse( data );
 
 

+ 12 - 0
src/Three.Legacy.js

@@ -45,6 +45,7 @@ import { AudioLoader } from './loaders/AudioLoader.js';
 import { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
 import { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
 import { DataTextureLoader } from './loaders/DataTextureLoader.js';
 import { DataTextureLoader } from './loaders/DataTextureLoader.js';
 import { JSONLoader } from './loaders/JSONLoader.js';
 import { JSONLoader } from './loaders/JSONLoader.js';
+import { ObjectLoader } from './loaders/ObjectLoader.js';
 import { TextureLoader } from './loaders/TextureLoader.js';
 import { TextureLoader } from './loaders/TextureLoader.js';
 import { Material } from './materials/Material.js';
 import { Material } from './materials/Material.js';
 import { LineBasicMaterial } from './materials/LineBasicMaterial.js';
 import { LineBasicMaterial } from './materials/LineBasicMaterial.js';
@@ -447,6 +448,17 @@ Object.assign( JSONLoader.prototype, {
 
 
 } );
 } );
 
 
+Object.assign( ObjectLoader.prototype, {
+
+	setTexturePath: function ( value ) {
+
+		console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
+		return this.setResourcePath( value );
+
+	}
+
+} );
+
 //
 //
 
 
 Object.assign( Box2.prototype, {
 Object.assign( Box2.prototype, {

+ 18 - 12
src/loaders/ObjectLoader.js

@@ -48,6 +48,7 @@ import { ImageLoader } from './ImageLoader.js';
 import { LoadingManager, DefaultLoadingManager } from './LoadingManager.js';
 import { LoadingManager, DefaultLoadingManager } from './LoadingManager.js';
 import { AnimationClip } from '../animation/AnimationClip.js';
 import { AnimationClip } from '../animation/AnimationClip.js';
 import { MaterialLoader } from './MaterialLoader.js';
 import { MaterialLoader } from './MaterialLoader.js';
+import { LoaderUtils } from './LoaderUtils.js';
 import { BufferGeometryLoader } from './BufferGeometryLoader.js';
 import { BufferGeometryLoader } from './BufferGeometryLoader.js';
 import { JSONLoader } from './JSONLoader.js';
 import { JSONLoader } from './JSONLoader.js';
 import { FileLoader } from './FileLoader.js';
 import { FileLoader } from './FileLoader.js';
@@ -61,7 +62,7 @@ import * as Curves from '../extras/curves/Curves.js';
 function ObjectLoader( manager ) {
 function ObjectLoader( manager ) {
 
 
 	this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
 	this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
-	this.texturePath = '';
+	this.resourcePath = '';
 
 
 }
 }
 
 
@@ -71,15 +72,13 @@ Object.assign( ObjectLoader.prototype, {
 
 
 	load: function ( url, onLoad, onProgress, onError ) {
 	load: function ( url, onLoad, onProgress, onError ) {
 
 
-		if ( this.texturePath === '' ) {
-
-			this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
-
-		}
-
 		var scope = this;
 		var scope = this;
 
 
+		var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
+		this.resourcePath = this.resourcePath || path;
+
 		var loader = new FileLoader( scope.manager );
 		var loader = new FileLoader( scope.manager );
+		loader.setPath( this.path );
 		loader.load( url, function ( text ) {
 		loader.load( url, function ( text ) {
 
 
 			var json = null;
 			var json = null;
@@ -113,9 +112,16 @@ Object.assign( ObjectLoader.prototype, {
 
 
 	},
 	},
 
 
-	setTexturePath: function ( value ) {
+	setPath: function ( value ) {
+
+		this.path = value;
+		return this;
+
+	},
+
+	setResourcePath: function ( value ) {
 
 
-		this.texturePath = value;
+		this.resourcePath = value;
 		return this;
 		return this;
 
 
 	},
 	},
@@ -418,7 +424,7 @@ Object.assign( ObjectLoader.prototype, {
 
 
 					case 'Geometry':
 					case 'Geometry':
 
 
-						geometry = geometryLoader.parse( data, this.texturePath ).geometry;
+						geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
 
 
 						break;
 						break;
 
 
@@ -550,7 +556,7 @@ Object.assign( ObjectLoader.prototype, {
 
 
 						var currentUrl = url[ j ];
 						var currentUrl = url[ j ];
 
 
-						var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.texturePath + currentUrl;
+						var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
 
 
 						images[ image.uuid ].push( loadImage( path ) );
 						images[ image.uuid ].push( loadImage( path ) );
 
 
@@ -560,7 +566,7 @@ Object.assign( ObjectLoader.prototype, {
 
 
 					// load single image
 					// load single image
 
 
-					var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
+					var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
 
 
 					images[ image.uuid ] = loadImage( path );
 					images[ image.uuid ] = loadImage( path );