From 963bcc8144224f248f6d4687d95d3b191c0712df Mon Sep 17 00:00:00 2001
From: Mugen87
Date: Wed, 26 Sep 2018 19:25:51 +0200
Subject: [PATCH] ObjectLoader: Added setPath(), setTexturePath() ->
setResourcePath().
---
docs/api/en/loaders/ObjectLoader.html | 13 +++++++-----
editor/js/Loader.js | 2 +-
src/Three.Legacy.js | 12 +++++++++++
src/loaders/ObjectLoader.js | 30 ++++++++++++++++-----------
4 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/docs/api/en/loaders/ObjectLoader.html b/docs/api/en/loaders/ObjectLoader.html
index 95a7c0f2e4..2fe83f2f67 100644
--- a/docs/api/en/loaders/ObjectLoader.html
+++ b/docs/api/en/loaders/ObjectLoader.html
@@ -85,9 +85,9 @@
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
- [property:String texturePath]
+ [property:String resourcePath]
- 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.
@@ -217,11 +217,14 @@
[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
- [method:ObjectLoader setTexturePath]( [param:String value] )
+ [method:ObjectLoader setPath]( [param:String value] )
- [page:String value] — The base path or URL from which textures will be loaded.
-
+ Set the base path for the original file.
+
+ [method:ObjectLoader setResourcePath]( [param:String value] )
+
+ Set the base path for dependent resources like textures.
Source
diff --git a/editor/js/Loader.js b/editor/js/Loader.js
index 1357e067ff..30b7c4841e 100644
--- a/editor/js/Loader.js
+++ b/editor/js/Loader.js
@@ -626,7 +626,7 @@ var Loader = function ( editor ) {
case 'object':
var loader = new THREE.ObjectLoader();
- loader.setTexturePath( scope.texturePath );
+ loader.setResourcePath( scope.texturePath );
var result = loader.parse( data );
diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js
index bcf4da484a..456d75b125 100644
--- a/src/Three.Legacy.js
+++ b/src/Three.Legacy.js
@@ -45,6 +45,7 @@ import { AudioLoader } from './loaders/AudioLoader.js';
import { CubeTextureLoader } from './loaders/CubeTextureLoader.js';
import { DataTextureLoader } from './loaders/DataTextureLoader.js';
import { JSONLoader } from './loaders/JSONLoader.js';
+import { ObjectLoader } from './loaders/ObjectLoader.js';
import { TextureLoader } from './loaders/TextureLoader.js';
import { Material } from './materials/Material.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, {
diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js
index 2ff101e72c..b951a645f6 100644
--- a/src/loaders/ObjectLoader.js
+++ b/src/loaders/ObjectLoader.js
@@ -48,6 +48,7 @@ import { ImageLoader } from './ImageLoader.js';
import { LoadingManager, DefaultLoadingManager } from './LoadingManager.js';
import { AnimationClip } from '../animation/AnimationClip.js';
import { MaterialLoader } from './MaterialLoader.js';
+import { LoaderUtils } from './LoaderUtils.js';
import { BufferGeometryLoader } from './BufferGeometryLoader.js';
import { JSONLoader } from './JSONLoader.js';
import { FileLoader } from './FileLoader.js';
@@ -61,7 +62,7 @@ import * as Curves from '../extras/curves/Curves.js';
function ObjectLoader( manager ) {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
- this.texturePath = '';
+ this.resourcePath = '';
}
@@ -71,15 +72,13 @@ Object.assign( ObjectLoader.prototype, {
load: function ( url, onLoad, onProgress, onError ) {
- if ( this.texturePath === '' ) {
-
- this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
-
- }
-
var scope = this;
+ var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
+ this.resourcePath = this.resourcePath || path;
+
var loader = new FileLoader( scope.manager );
+ loader.setPath( this.path );
loader.load( url, function ( text ) {
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;
},
@@ -418,7 +424,7 @@ Object.assign( ObjectLoader.prototype, {
case 'Geometry':
- geometry = geometryLoader.parse( data, this.texturePath ).geometry;
+ geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
break;
@@ -550,7 +556,7 @@ Object.assign( ObjectLoader.prototype, {
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 ) );
@@ -560,7 +566,7 @@ Object.assign( ObjectLoader.prototype, {
// 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 );
--
GitLab