提交 3116de8c 编写于 作者: M Mugen87

JSONLoader: Add setPath(), rename setTexturePath() to setResourcePath()

上级 eb6ef2e3
......@@ -93,23 +93,27 @@
Begin loading from url and pass the <em>JSON</em> to onLoad.
</p>
<h3>[method:Object3D parse]( [param:Object json], [param:String path] )</h3>
<p>
[page:String json] — JSON object to parse.<br />
[page:String path] — Base path for resources if no resource path is defined.<br /><br />
Parse a <em>JSON</em> structure and return an [page:object] containing the parsed [page:Geometry geometry] and [page:Array materials].
</p>
<h3>[method:JSONLoader setCrossOrigin]( [param:String value] )</h3>
<p>
Set the [page:.crossOrigin] attribute.
</p>
<h3>[method:JSONLoader setTexturePath]( [param:String texturePath] )</h3>
<h3>[method:JSONLoader setPath]( [param:String value] )</h3>
<p>
Set the base path or URL from which to load files. This can be useful if
you are loading many files from the same directory.
Set the base path for the original file.
</p>
<h3>[method:Object3D parse]( [param:Object json], [param:String texturePath] )</h3>
<h3>[method:JSONLoader setResourcePath]( [param:String value] )</h3>
<p>
[page:String json] — JSON object to parse.<br />
[page:String texturePath] — Base path for textures.<br /><br />
Parse a <em>JSON</em> structure and return an [page:object] containing the parsed [page:Geometry geometry] and [page:Array materials].
Set the base path for dependent resources like textures.
</p>
<h2>Source</h2>
......
......@@ -577,7 +577,7 @@ var Loader = function ( editor ) {
case 'geometry':
var loader = new THREE.JSONLoader();
loader.setTexturePath( scope.texturePath );
loader.setResourcePath( scope.texturePath );
var result = loader.parse( data );
......
......@@ -44,6 +44,7 @@ import { FileLoader } from './loaders/FileLoader.js';
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 { TextureLoader } from './loaders/TextureLoader.js';
import { Material } from './materials/Material.js';
import { LineBasicMaterial } from './materials/LineBasicMaterial.js';
......@@ -435,6 +436,17 @@ export function BinaryTextureLoader( manager ) {
}
Object.assign( JSONLoader.prototype, {
setTexturePath: function ( value ) {
console.warn( 'THREE.JSONLoader: .setTexturePath() has been renamed to .setResourcePath().' );
return this.setResourcePath( value );
}
} );
//
Object.assign( Box2.prototype, {
......
......@@ -38,9 +38,10 @@ Object.assign( JSONLoader.prototype, {
var scope = this;
var texturePath = this.texturePath && ( typeof this.texturePath === 'string' ) ? this.texturePath : LoaderUtils.extractUrlBase( url );
var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
var loader = new FileLoader( this.manager );
loader.setPath( this.path );
loader.setWithCredentials( this.withCredentials );
loader.load( url, function ( text ) {
......@@ -64,23 +65,30 @@ Object.assign( JSONLoader.prototype, {
}
var object = scope.parse( json, texturePath );
var object = scope.parse( json, path );
onLoad( object.geometry, object.materials );
}, onProgress, onError );
},
setCrossOrigin: function ( value ) {
setPath: function ( value ) {
this.crossOrigin = value;
this.path = value;
return this;
},
setTexturePath: function ( value ) {
setResourcePath: function ( value ) {
this.texturePath = value;
this.resourcePath = value;
return this;
},
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
return this;
},
......@@ -528,7 +536,7 @@ Object.assign( JSONLoader.prototype, {
}
return function parse( json, texturePath ) {
return function parse( json, path ) {
if ( json.data !== undefined ) {
......@@ -563,7 +571,7 @@ Object.assign( JSONLoader.prototype, {
} else {
var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
var materials = Loader.prototype.initMaterials( json.materials, this.resourcePath || path, this.crossOrigin );
return { geometry: geometry, materials: materials };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册