Browse Source

Merge pull request #10234 from looeee/docs/loadingManager/improve

Updated LoadingManager and DefaultLoadingManager docs
Mr.doob 8 năm trước cách đây
mục cha
commit
dc97c8df31

+ 49 - 6
docs/api/loaders/DefaultLoadingManager.html

@@ -10,20 +10,63 @@
 	<body>
 		<h1>[name]</h1>
 
-		<div class="desc">An instance of the [page:LoadingManager LoadingManager], used by most loaders
-			when no custom manager has been specified.
+		<div class="desc">A global instance of the [page:LoadingManager LoadingManager], used by most loaders
+			when no custom manager has been specified.<br /><br />
+
+		  This will be sufficient for most purposes, however there may be times when you desire seperate loading managers
+			for say, textures and models.
+		</div>
+
+		<h2>Example</h2>
+
+		<div>
+			[example:webgl_loader_scene WebGL / loader / scene]<br />
 		</div>
 
+		<div>
+			You can optionally set the [page:LoadingManager.onStart onStart], [page:LoadingManager.onLoad onLoad],
+			[page:LoadingManager.onProgress onProgress], [page:LoadingManager.onStart onError] functions for the manager.
+			These will then apply to any loaders using the DefaultLoadingManager.<br /><br />
+
+			Note that these shouldn't be confused with the similarly named functions of individual loaders,
+			as they are intended for displaying information about the overall status of loading,
+			rather than dealing with the data that has been loaded.
+		</div>
+		<code>
+THREE.DefaultLoadingManager.onStart = function ( url, itemsLoaded, itemsTotal ) {
+
+	console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
+
+};
+
+THREE.DefaultLoadingManager.onLoad = function ( ) {
+
+	console.log( 'Loading Complete!');
+
+};
+
+
+THREE.DefaultLoadingManager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
+
+	console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
+
+};
+
+THREE.DefaultLoadingManager.onError = function ( url ) {
+
+	console.log( 'There was an error loading ' + url );
+
+};
+		</code>
+
 
 		<h2>Properties</h2>
 
-		See the [page:LoadingManager LoadingManager] for properties.
+		<div>See the [page:LoadingManager LoadingManager] page for details of properties.</div>
 
 		<h2>Methods</h2>
 
-		See the [page:LoadingManager LoadingManager] for methods.
-
-		<h2>Example</h2>
+		<div>See the [page:LoadingManager LoadingManager] page for details of methods.</div>
 
 		<h2>Source</h2>
 

+ 87 - 23
docs/api/loaders/LoadingManager.html

@@ -10,12 +10,52 @@
 	<body>
 		<h1>[name]</h1>
 
-		<div class="desc">Handles and keeps track of loaded and pending data.</div>
+		<div class="desc">
+			Handles and keeps track of loaded and pending data. A default global instance of this class
+			is created and used by loaders if not supplied manually - see [page:DefaultLoadingManager].<br /><br />
+
+			In general that should be sufficient, however there are times when it can be useful to have seperate loaders -
+			for example if you want to show seperate loading bars for objects and textures.
+
+		</div>
+
+
+		<h2>Example</h2>
+
+		<div>
+			[example:webgl_loader_babylon WebGL / loader / babylon]<br />
+			[example:webgl_loader_fbx WebGL / loader / fbx]<br />
+			[example:webgl_loader_obj WebGL / loader / obj]<br />
+			[example:webgl_materials_reflectivity WebGL / materials / reflectivity]<br />
+			[example:webgl_postprocessing_outline WebGL / postprocesing / outline]<br />
+			[example:webgl_terrain_dynamic WebGL / terrain / dynamic]
+		</div>
+
+
 		<code>
 		var manager = new THREE.LoadingManager();
-		manager.onProgress = function ( item, loaded, total ) {
+		manager.onStart = function ( url, itemsLoaded, itemsTotal ) {
+
+			console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
+
+		};
+
+		manager.onLoad = function ( ) {
+
+			console.log( 'Loading complete!');
+
+		};
+
+
+		manager.onProgress = function ( url, itemsLoaded, itemsTotal ) {
+
+			console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
+
+		};
+
+		manager.onError = function ( url ) {
 
-			console.log( item, loaded, total );
+			console.log( 'There was an error loading ' + url );
 
 		};
 
@@ -32,57 +72,81 @@
 
 		<h3>[name]( [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
 		<div>
-		[page:Function onLoad] — The function that needs to be called when all loaders are done.<br />
-		[page:Function onProgress] — The function that needs to be called when an item is complete.<br />
-		[page:Function onError] — The function that needs to be called when an item is errors.
-		</div>
-		<div>
-		Creates a [name].
+		[page:Function onLoad] — (optional) this function will be called when all loaders are done.<br />
+		[page:Function onProgress] — (optional) this function will be called when an item is complete.<br />
+		[page:Function onError] — (optional) this function will be called a loader encounters errors. <br />
+
+		Creates a new [name].
 		</div>
 
 
 		<h2>Properties</h2>
 
+		<h3>[property:Function onStart]</h3>
+		<div>
+			This function will be called when loading starts.
+			The arguments are:<br />
+			[page:String url] — The url of the item just loaded.<br />
+			[page:Integer itemsLoaded] — the number  of items already loaded so far.<br />
+			[page:Iteger itemsTotal] — the total amount of items to be loaded.<br /><br />
+
+			By default this is undefined.
+		</div>
+
 		<h3>[property:Function onLoad]</h3>
 		<div>
-		The function that needs to be called when all loaders are done.
+			This function will be called when all loading is completed. By default this is undefined,
+			unless passed in the constructor.
 		</div>
 
 		<h3>[property:Function onProgress]</h3>
 		<div>
-		The function that needs to be called when an item is complete. The arguments are url(The url of the item just loaded),<br />
-		loaded(the amount of items already loaded), total( The total amount of items to be loaded.)
+		This function will be called when an item is complete.
+		The arguments are:<br />
+		[page:String url] — The url of the item just loaded.<br />
+		[page:Integer itemsLoaded] — the number  of items already loaded so far.<br />
+		[page:Iteger itemsTotal] — the total amount of items to be loaded.<br /><br />
+
+		By default this is undefined, unless passed in the constructor.
 		</div>
 
 		<h3>[property:Function onError]</h3>
 		<div>
-		The function that needs to be called when an item errors.
+			This function will be called when any item errors, with the argument:<br />
+			[page:String url] — The url of the item that errored.<br /><br />
+
+			By default this is undefined, unless passed in the constructor.
 		</div>
 
 
 		<h2>Methods</h2>
 
-		<h3>[method:null itemStart]( [page:String url] )</h3>
 		<div>
-		[page:String url] — the url to load
+			<em>Note: The following methods are designed to be called internally by loaders. You shouldn't call
+			them directly.</em>
 		</div>
+
+		<h3>[method:null itemStart]( [page:String url] )</h3>
 		<div>
-		This should be called by any loader used by the manager when the loader starts loading an url. These shouldn't be called outside a loader.
+		[page:String url] — the url to load<br /><br />
+
+		This should be called by any loader used by the manager when the loader starts loading an url.
 		</div>
 
 		<h3>[method:null itemEnd]( [page:String url] )</h3>
 		<div>
-		[page:String url] — the loaded url
-		</div>
-		<div>
-		This should be called by any loader used by the manager when the loader ended loading an url.  These shouldn't be called outside a loader.
-		</div>
+		[page:String url] — the loaded url<br /><br />
 
+		This should be called by any loader used by the manager when the loader ended loading an url.
+		</div>
 
-		<h2>Example</h2>
 
-		[example:webgl_loader_obj]
+		<h3>[method:null itemError]( [page:String url] )</h3>
+		<div>
+		[page:String url] — the loaded url<br /><br />
 
+		This should be called by any loader used by the manager when the loader errors loading an url.
+		</div>
 
 		<h2>Source</h2>