未验证 提交 c1a175dd 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #14977 from Mugen87/dev9

ObjectLoader: Added setPath(), setTexturePath() -> setResourcePath().
......@@ -85,9 +85,9 @@
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
</p>
<h3>[property:String texturePath]</h3>
<h3>[property:String resourcePath]</h3>
<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.
</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.
</p>
<h3>[method:ObjectLoader setTexturePath]( [param:String value] )</h3>
<h3>[method:ObjectLoader setPath]( [param:String value] )</h3>
<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>
<h2>Source</h2>
......
......@@ -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 );
......
......@@ -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, {
......
......@@ -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 );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册