Browse Source

Loader: Introduce new API.

Mugen87 6 years ago
parent
commit
0d253f07a3

+ 50 - 3
docs/api/en/loaders/Loader.html

@@ -16,9 +16,12 @@
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>
 
 
 
 
-		<h3>[name]()</h3>
+		<h3>[name]( [param:LoadingManager manager] )</h3>
 		<p>
 		<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>
 		</p>
 
 
 
 
@@ -27,7 +30,51 @@
 		<h3>[property:string crossOrigin]</h3>
 		<h3>[property:string crossOrigin]</h3>
 		<p>
 		<p>
 		The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
 		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>
 		</p>
 
 
 		<h2>Handlers</h2>
 		<h2>Handlers</h2>

+ 4 - 33
docs/api/en/loaders/ObjectLoader.html

@@ -8,6 +8,8 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	</head>
 	<body>
 	<body>
+		[page:Loader] &rarr;
+
 		<h1>[name]</h1>
 		<h1>[name]</h1>
 
 
 		<p class="desc">
 		<p class="desc">
@@ -66,27 +68,11 @@
 		Creates a new [name].
 		Creates a new [name].
 		</p>
 		</p>
 
 
-
 		<h2>Properties</h2>
 		<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>
 		<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>
 		<h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
 		<p>
 		<p>
@@ -206,21 +192,6 @@
 		</ul>
 		</ul>
 		</p>
 		</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>
 		<h2>Source</h2>
 
 
 		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
 		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 14 - 7
src/loaders/Loader.d.ts

@@ -1,19 +1,26 @@
 import { LoaderHandler } from './FileLoader';
 import { LoaderHandler } from './FileLoader';
-
-// Loaders //////////////////////////////////////////////////////////////////////////////////
+import { LoadingManager } from './LoadingManager';
 
 
 /**
 /**
  * Base class for implementing loaders.
  * Base class for implementing loaders.
  */
  */
 export class Loader {
 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;
 	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;
 	static Handlers: LoaderHandler;
 
 

+ 42 - 7
src/loaders/Loader.js

@@ -1,8 +1,49 @@
+import { DefaultLoadingManager } from './LoadingManager.js';
+
 /**
 /**
  * @author alteredq / http://alteredqualia.com/
  * @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 = {
 Loader.Handlers = {
 
 
@@ -37,11 +78,5 @@ Loader.Handlers = {
 
 
 };
 };
 
 
-Object.assign( Loader.prototype, {
-
-	crossOrigin: 'anonymous'
-
-} );
-
 
 
 export { Loader };
 export { Loader };

+ 2 - 7
src/loaders/ObjectLoader.d.ts

@@ -1,25 +1,20 @@
+import { Loader } from './Loader';
 import { LoadingManager } from './LoadingManager';
 import { LoadingManager } from './LoadingManager';
 import { Object3D } from './../core/Object3D';
 import { Object3D } from './../core/Object3D';
 import { Texture } from './../textures/Texture';
 import { Texture } from './../textures/Texture';
 import { Material } from './../materials/Material';
 import { Material } from './../materials/Material';
 import { AnimationClip } from './../animation/AnimationClip';
 import { AnimationClip } from './../animation/AnimationClip';
 
 
-export class ObjectLoader {
+export class ObjectLoader extends Loader {
 
 
 	constructor( manager?: LoadingManager );
 	constructor( manager?: LoadingManager );
 
 
-	manager: LoadingManager;
-	texturePass: string;
-	crossOrigin: string;
-
 	load(
 	load(
 		url: string,
 		url: string,
 		onLoad?: <ObjectType extends Object3D>( object: ObjectType ) => void,
 		onLoad?: <ObjectType extends Object3D>( object: ObjectType ) => void,
 		onProgress?: ( event: ProgressEvent ) => void,
 		onProgress?: ( event: ProgressEvent ) => void,
 		onError?: ( event: Error | ErrorEvent ) => void
 		onError?: ( event: Error | ErrorEvent ) => void
 	): void;
 	): void;
-	setTexturePath( value: string ): void;
-	setCrossOrigin( crossOrigin: string ): void;
 	parse<T extends Object3D>( json: any, onLoad?: ( object: Object3D ) => void ): T;
 	parse<T extends Object3D>( json: any, onLoad?: ( object: Object3D ) => void ): T;
 	parseGeometries( json: any ): any[]; // Array of BufferGeometry or Geometry or Geometry2.
 	parseGeometries( json: any ): any[]; // Array of BufferGeometry or Geometry or Geometry2.
 	parseMaterials( json: any, textures: Texture[] ): Material[]; // Array of Classes that inherits from Matrial.
 	parseMaterials( json: any, textures: Texture[] ): Material[]; // Array of Classes that inherits from Matrial.

+ 6 - 27
src/loaders/ObjectLoader.js

@@ -45,11 +45,12 @@ import { Scene } from '../scenes/Scene.js';
 import { CubeTexture } from '../textures/CubeTexture.js';
 import { CubeTexture } from '../textures/CubeTexture.js';
 import { Texture } from '../textures/Texture.js';
 import { Texture } from '../textures/Texture.js';
 import { ImageLoader } from './ImageLoader.js';
 import { ImageLoader } from './ImageLoader.js';
-import { LoadingManager, DefaultLoadingManager } from './LoadingManager.js';
+import { LoadingManager } 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 { LoaderUtils } from './LoaderUtils.js';
 import { BufferGeometryLoader } from './BufferGeometryLoader.js';
 import { BufferGeometryLoader } from './BufferGeometryLoader.js';
+import { Loader } from './Loader.js';
 import { FileLoader } from './FileLoader.js';
 import { FileLoader } from './FileLoader.js';
 import * as Geometries from '../geometries/Geometries.js';
 import * as Geometries from '../geometries/Geometries.js';
 import * as Curves from '../extras/curves/Curves.js';
 import * as Curves from '../extras/curves/Curves.js';
@@ -60,20 +61,19 @@ import * as Curves from '../extras/curves/Curves.js';
 
 
 function ObjectLoader( manager ) {
 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 ) {
 	load: function ( url, onLoad, onProgress, onError ) {
 
 
 		var scope = this;
 		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;
 		this.resourcePath = this.resourcePath || path;
 
 
 		var loader = new FileLoader( scope.manager );
 		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 ) {
 	parse: function ( json, onLoad ) {
 
 
 		var shapes = this.parseShape( json.shapes );
 		var shapes = this.parseShape( json.shapes );