提交 0d253f07 编写于 作者: M Mugen87

Loader: Introduce new API.

上级 7abf4498
......@@ -16,9 +16,12 @@
<h2>Constructor</h2>
<h3>[name]()</h3>
<h3>[name]( [param:LoadingManager manager] )</h3>
<p>
Creates a new [name]. This should be called as base class.
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
</p>
<p>
Creates a new [name].
</p>
......@@ -27,7 +30,51 @@
<h3>[property:string crossOrigin]</h3>
<p>
The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
Default is *"anonymous"*.
Default is *anonymous*.
</p>
<h3>[property:LoadingManager manager]</h3>
<p>
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
</p>
<h3>[property:String path]</h3>
<p>
The base path from which the asset will be loaded.
Default is the empty string.
</p>
<h3>[property:String resourcePath]</h3>
<p>
The base path from which additional resources like textures will be loaded.
Default is the empty string.
</p>
<h2>Methods</h2>
<h3>[method:void load]()</h3>
<p>
This method needs to be implement by all concrete loaders. It holds the logic for loading the asset from the backend.
</p>
<h3>[method:void parse]()</h3>
<p>
This method needs to be implement by all concrete loaders. It holds the logic for parsing the asset into three.js entities.
</p>
<h3>[method:Loader setCrossOrigin]( [param:String crossOrigin] )</h3>
<p>
[page:String crossOrigin] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
</p>
<h3>[method:Loader setPath]( [param:String path] )</h3>
<p>
[page:String path] — Set the base path for the asset.
</p>
<h3>[method:Loader setResourcePath]( [param:String resourcePath] )</h3>
<p>
[page:String resourcePath] — Set the base path for dependent resources like textures.
</p>
<h2>Handlers</h2>
......
......@@ -8,6 +8,8 @@
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
[page:Loader] &rarr;
<h1>[name]</h1>
<p class="desc">
......@@ -66,27 +68,11 @@
Creates a new [name].
</p>
<h2>Properties</h2>
<h3>[property:String crossOrigin]</h3>
<p>
If set, assigns the [link:https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes crossOrigin]
attribute of the image to the value of *crossOrigin*, prior to starting the load. Default is *"anonymous"*.
</p>
<h3>[property:LoadingManager manager]</h3>
<p>
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
</p>
<h3>[property:String resourcePath]</h3>
<p>
The base path or URL from which additional resources like textuures will be loaded. See [page:.setResourcePath].
Default is the empty string.
</p>
<p>See the base [page:Loader] class for common properties.</p>
<h2>Methods</h2>
<p>See the base [page:Loader] class for common methods.</p>
<h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
<p>
......@@ -206,21 +192,6 @@
</ul>
</p>
<h3>[method:ObjectLoader setCrossOrigin]( [param:String value] )</h3>
<p>
[page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
</p>
<h3>[method:ObjectLoader setPath]( [param:String value] )</h3>
<p>
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>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......
import { LoaderHandler } from './FileLoader';
// Loaders //////////////////////////////////////////////////////////////////////////////////
import { LoadingManager } from './LoadingManager';
/**
* Base class for implementing loaders.
*/
export class Loader {
constructor();
constructor( manager?: LoadingManager );
/**
* default — anonymous.
* If set, assigns the crossOrigin attribute of the image to the value of crossOrigin, prior to starting the load.
*/
crossOrigin: string;
path: string;
resourcePath: string;
manager: LoadingManager;
/*
load(): void;
parse(): void;
*/
setCrossOrigin( crossOrigin: string ): this;
setPath( path: string ): this;
setResourcePath( resourcePath: string ): this;
static Handlers: LoaderHandler;
......
import { DefaultLoadingManager } from './LoadingManager.js';
/**
* @author alteredq / http://alteredqualia.com/
*/
function Loader() {}
function Loader( manager ) {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
this.crossOrigin = 'anonymous';
this.path = '';
this.resourcePath = '';
}
Object.assign( Loader.prototype, {
load: function ( /* url, onLoad, onProgress, onError */ ) {},
parse: function ( /* data */ ) {},
setCrossOrigin: function ( crossOrigin ) {
this.crossOrigin = crossOrigin;
return this;
},
setPath: function ( path ) {
this.path = path;
return this;
},
setResourcePath: function ( resourcePath ) {
this.resourcePath = resourcePath;
return this;
}
} );
//
Loader.Handlers = {
......@@ -37,11 +78,5 @@ Loader.Handlers = {
};
Object.assign( Loader.prototype, {
crossOrigin: 'anonymous'
} );
export { Loader };
import { Loader } from './Loader';
import { LoadingManager } from './LoadingManager';
import { Object3D } from './../core/Object3D';
import { Texture } from './../textures/Texture';
import { Material } from './../materials/Material';
import { AnimationClip } from './../animation/AnimationClip';
export class ObjectLoader {
export class ObjectLoader extends Loader {
constructor( manager?: LoadingManager );
manager: LoadingManager;
texturePass: string;
crossOrigin: string;
load(
url: string,
onLoad?: <ObjectType extends Object3D>( object: ObjectType ) => void,
onProgress?: ( event: ProgressEvent ) => void,
onError?: ( event: Error | ErrorEvent ) => void
): void;
setTexturePath( value: string ): void;
setCrossOrigin( crossOrigin: string ): void;
parse<T extends Object3D>( json: any, onLoad?: ( object: Object3D ) => void ): T;
parseGeometries( json: any ): any[]; // Array of BufferGeometry or Geometry or Geometry2.
parseMaterials( json: any, textures: Texture[] ): Material[]; // Array of Classes that inherits from Matrial.
......
......@@ -45,11 +45,12 @@ import { Scene } from '../scenes/Scene.js';
import { CubeTexture } from '../textures/CubeTexture.js';
import { Texture } from '../textures/Texture.js';
import { ImageLoader } from './ImageLoader.js';
import { LoadingManager, DefaultLoadingManager } from './LoadingManager.js';
import { LoadingManager } 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 { Loader } from './Loader.js';
import { FileLoader } from './FileLoader.js';
import * as Geometries from '../geometries/Geometries.js';
import * as Curves from '../extras/curves/Curves.js';
......@@ -60,20 +61,19 @@ import * as Curves from '../extras/curves/Curves.js';
function ObjectLoader( manager ) {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
this.resourcePath = '';
Loader.call( this, manager );
}
Object.assign( ObjectLoader.prototype, {
ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
crossOrigin: 'anonymous',
constructor: ObjectLoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
this.resourcePath = this.resourcePath || path;
var loader = new FileLoader( scope.manager );
......@@ -111,27 +111,6 @@ Object.assign( ObjectLoader.prototype, {
},
setPath: function ( value ) {
this.path = value;
return this;
},
setResourcePath: function ( value ) {
this.resourcePath = value;
return this;
},
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
return this;
},
parse: function ( json, onLoad ) {
var shapes = this.parseShape( json.shapes );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册