You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							111 lines
						
					
					
						
							4.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							111 lines
						
					
					
						
							4.2 KiB
						
					
					
				
								<!DOCTYPE html>
							 | 
						|
								<html lang="en">
							 | 
						|
									<head>
							 | 
						|
										<meta charset="utf-8" />
							 | 
						|
										<base href="../../../" />
							 | 
						|
										<script src="page.js"></script>
							 | 
						|
										<link type="text/css" rel="stylesheet" href="page.css" />
							 | 
						|
									</head>
							 | 
						|
									<body>
							 | 
						|
										[page:Loader] →
							 | 
						|
								
							 | 
						|
										<h1>[name]</h1>
							 | 
						|
								
							 | 
						|
										<p class="desc">
							 | 
						|
											A low level class for loading resources with Fetch, used internally by most loaders.
							 | 
						|
											It can also be used directly to load any file type that does not have a loader.
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
										<h2>Code Example</h2>
							 | 
						|
										<code>
							 | 
						|
										const loader = new THREE.FileLoader();
							 | 
						|
								
							 | 
						|
										//load a text file and output the result to the console
							 | 
						|
										loader.load(
							 | 
						|
											// resource URL
							 | 
						|
											'example.txt',
							 | 
						|
								
							 | 
						|
											// onLoad callback
							 | 
						|
											function ( data ) {
							 | 
						|
												// output the text to the console
							 | 
						|
												console.log( data )
							 | 
						|
											},
							 | 
						|
								
							 | 
						|
											// onProgress callback
							 | 
						|
											function ( xhr ) {
							 | 
						|
												console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
							 | 
						|
											},
							 | 
						|
								
							 | 
						|
											// onError callback
							 | 
						|
											function ( err ) {
							 | 
						|
												console.error( 'An error happened' );
							 | 
						|
											}
							 | 
						|
										);
							 | 
						|
										</code>
							 | 
						|
								
							 | 
						|
										<p>
							 | 
						|
											*Note:* The cache must be enabled using
							 | 
						|
											<code>THREE.Cache.enabled = true;</code>
							 | 
						|
											This is a global property and only needs to be set once to be used by all loaders that use FileLoader internally.
							 | 
						|
											[page:Cache Cache] is a cache module that holds the response from each request made through this loader, so each file is requested once.
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
								
							 | 
						|
										<h2>Constructor</h2>
							 | 
						|
								
							 | 
						|
										<h3>[name] ( [param:LoadingManager manager] )</h3>
							 | 
						|
										<p>
							 | 
						|
											[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
							 | 
						|
											Default is [page:DefaultLoadingManager].
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
										<h2>Properties</h2>
							 | 
						|
										<p>See the base [page:Loader] class for common properties.</p>
							 | 
						|
								
							 | 
						|
										<h3>[property:String mimeType]</h3>
							 | 
						|
										<p>
							 | 
						|
											The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
							 | 
						|
											See [page:.setMimeType]. Default is `undefined`.
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
										<h3>[property:String responseType]</h3>
							 | 
						|
										<p>The expected response type. See [page:.setResponseType]. Default is `undefined`.</p>
							 | 
						|
								
							 | 
						|
										<h2>Methods</h2>
							 | 
						|
										<p>See the base [page:Loader] class for common methods.</p>
							 | 
						|
								
							 | 
						|
										<h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
							 | 
						|
										<p>
							 | 
						|
											[page:String url] — the path or URL to the file. This can also be a
							 | 
						|
												[link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
							 | 
						|
											[page:Function onLoad] (optional) — Will be called when loading completes. The argument will be the loaded response.<br />
							 | 
						|
											[page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the ProgressEvent instance, which contains .[page:Boolean lengthComputable], .[page:Integer total] and .[page:Integer loaded]. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
							 | 
						|
											[page:Function onError] (optional) — Will be called if an error occurs.<br /><br />
							 | 
						|
								
							 | 
						|
											Load the URL and pass the response to the onLoad function.
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
										<h3>[method:this setMimeType]( [param:String mimeType] )</h3>
							 | 
						|
										<p>
							 | 
						|
											Set the expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType]
							 | 
						|
											of the file being loaded. Note that in many cases this will be determined automatically, so by default it is `undefined`.
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
										<h3>[method:this setResponseType]( [param:String responseType] )</h3>
							 | 
						|
										<p>
							 | 
						|
											Change the response type. Valid values are:<br />
							 | 
						|
											[page:String text] or empty string (default) - returns the data as [page:String String].<br />
							 | 
						|
											[page:String arraybuffer] - loads the data into a [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer] and returns that.<br />
							 | 
						|
											[page:String blob] - returns the data as a [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].<br />
							 | 
						|
											[page:String document] - parses the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
							 | 
						|
											[page:String json] - parses the file using [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse].<br />
							 | 
						|
										</p>
							 | 
						|
								
							 | 
						|
								
							 | 
						|
										<h2>Source</h2>
							 | 
						|
								
							 | 
						|
										<p>
							 | 
						|
											[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
							 | 
						|
										</p>
							 | 
						|
									</body>
							 | 
						|
								</html>
							 | 
						|
								
							 |