forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileLoader.html
148 lines (116 loc) · 5.35 KB
/
FileLoader.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<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" />
</head>
<body>
<h1>[name]</h1>
<div class="desc">
A low level class for loading resources with XMLHttpRequest, used internaly by most loaders.
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(
// 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>
<h2>Constructor</h2>
<h3>[name]( [page:LoadingManager manager] )</h3>
<div>
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
Default is [page:DefaultLoadingManager].
</div>
<h2>Properties</h2>
<h3>[property:Cache cache]</h3>
<div>
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.
</div>
<h3>[property:LoadingManager manager]</h3>
<div>
The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
</div>
<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>
<h3>[property:String responseType]</h3>
<div>The expected response type. See [page:.setResponseType]. Default is *undefined*.</div>
<h3>[property:String withCredentials]</h3>
<div>
Whether the XMLHttpRequest uses credentials - see [page:.setWithCredentials].
Default is *undefined*.
</div>
<h2>Methods</h2>
<h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
<div>
[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] — Will be called when loading completes. The argument will be the loaded response.<br />
[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 />
[page:Function onError] — Will be called if an error occurs.<br /><br />
Load the URL and pass the response to the onLoad function.
</div>
<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>
<h3>[method:FileLoader setPath]( [page:String path] )</h3>
<div>
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.
</div>
<h3>[method:FileLoader setResponseType]( [page:String responseType] )</h3>
<div>
[page:String responseType] — Default is '' (empty string).<br /><br />
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 />
</div>
<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>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</body>
</html>