FileLoader.html 5.4 KB
Newer Older
1 2
<!DOCTYPE html>
<html lang="en">
3
	<head>
M
Mr.doob 已提交
4 5 6 7 8
		<meta charset="utf-8" />
		<base href="../../" />
		<script src="list.js"></script>
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
9 10
	</head>
	<body>
M
Mr.doob 已提交
11

12
		<h1>[name]</h1>
M
Mr.doob 已提交
13

L
looeee 已提交
14
		<div class="desc">
P
paulmasson 已提交
15
			A low level class for loading resources with XMLHttpRequest, used internaly by most loaders.
L
looeee 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28
			It can also be used directly to load any file type that does not have a loader.
		</div>

		<h2>Example</h2>
		<div>
			[example:webgl_loader_msgpack WebGL / loader / msgpack]<br />
			[example:webgl_morphtargets_human WebGL / morphtargets / human]<br />
		</div>
		<code>
var loader = new THREE.FileLoader();

//load a text file a output the result to the console
loader.load(
L
looeee 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    // resource URL
    'example.txt',

    // Function when resource is loaded
    function ( data ) {
        // output the text to the console
        console.log( data )
    },

    // Function called when download progresses
    function ( xhr ) {
        console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
    },

    // Function called when download errors
    function ( xhr ) {
        console.error( 'An error happened' );
    }
);
L
looeee 已提交
48
		</code>
49

50
		<h2>Constructor</h2>
M
Mr.doob 已提交
51

52
		<h3>[name]( [page:LoadingManager manager] )</h3>
53
		<div>
L
looeee 已提交
54 55
		[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
		Default is [page:DefaultLoadingManager].
56
		</div>
M
Mr.doob 已提交
57 58


59
		<h2>Properties</h2>
M
Mr.doob 已提交
60

61
		<h3>[property:Cache cache]</h3>
62
		<div>
L
looeee 已提交
63 64 65 66 67 68
			A reference to [page:Cache Cache] that hold the response from each request made
			through this loader, so each file is requested once.<br /><br />

			<em>Note:</em>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.
69
		</div>
M
Mr.doob 已提交
70

L
looeee 已提交
71 72 73 74 75
		<h3>[property:LoadingManager manager]</h3>
		<div>
			The [page:LoadingManager loadingManager]  the loader is using. Default is [page:DefaultLoadingManager].
		</div>

L
looeee 已提交
76 77 78 79 80 81 82 83 84
		<h3>[property:String mimeType]</h3>
		<div>
			The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
			See [page:.setMimeType]. Default is *undefined*.
		</div>

		<h3>[property:String path]</h3>
		<div>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</div>

85
		<h3>[property:String responseType]</h3>
L
looeee 已提交
86 87 88
		<div>The expected response type. See [page:.setResponseType]. Default is *undefined*.</div>

		<h3>[property:String withCredentials]</h3>
89
		<div>
L
looeee 已提交
90
			Whether the XMLHttpRequest uses credentials - see [page:.setWithCredentials].
L
looeee 已提交
91
			Default is *undefined*.
92
		</div>
M
Mr.doob 已提交
93 94


L
looeee 已提交
95

96
		<h2>Methods</h2>
M
Mr.doob 已提交
97

98
		<h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
99
		<div>
L
looeee 已提交
100 101
		[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 />
L
looeee 已提交
102
		[page:Function onLoad] — Will be called when loading completes. The argument will be the loaded response.<br />
P
paulmasson 已提交
103 104
		[page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance,
			which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
L
looeee 已提交
105 106
		[page:Function onError] — Will be called if an error occurs.<br /><br />

L
looeee 已提交
107
		Load the URL and pass the response to the onLoad function.
108
		</div>
109

L
looeee 已提交
110 111 112 113 114
		<h3>[method:FileLoader setMimeType]( [page:String mimeType] )</h3>
		<div>
			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*.
		</div>
L
looeee 已提交
115

L
looeee 已提交
116 117
		<h3>[method:FileLoader setPath]( [page:String path] )</h3>
		<div>
L
looeee 已提交
118 119
			Set the base path or URL from which to load files. This can be useful if
			you are loading many models from the same directory.
L
looeee 已提交
120
		</div>
121

L
looeee 已提交
122
		<h3>[method:FileLoader setResponseType]( [page:String responseType] )</h3>
123
		<div>
L
looeee 已提交
124
		[page:String responseType] — Default is '' (empty string).<br /><br />
L
looeee 已提交
125 126 127 128 129 130 131 132

		Change the response type. Valid values are:<br />
		[page:String text], empty string (default), or any other value. Any file type, returns the unprocessed file data.<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] - parse the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
		[page:String json] - parse the file using [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse].<br />

133
		</div>
134

L
looeee 已提交
135 136 137 138 139 140 141 142 143
		<h3>[method:FileLoader setWithCredentials]( [page:Boolean value] )</h3>
		Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
		TLS client certificates. See
		[link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].<br />
		Note that this has no effect if you are loading files locally or from the same domain.
		<div>

		</div>

144 145 146 147
		<h2>Source</h2>

		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
	</body>
148
</html>