FileLoader.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Loader] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. A low level class for loading resources with XMLHttpRequest, used internaly by most loaders.
  15. It can also be used directly to load any file type that does not have a loader.
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. var loader = new THREE.FileLoader();
  20. //load a text file and output the result to the console
  21. loader.load(
  22. // resource URL
  23. 'example.txt',
  24. // onLoad callback
  25. function ( data ) {
  26. // output the text to the console
  27. console.log( data )
  28. },
  29. // onProgress callback
  30. function ( xhr ) {
  31. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  32. },
  33. // onError callback
  34. function ( err ) {
  35. console.error( 'An error happened' );
  36. }
  37. );
  38. </code>
  39. <p>
  40. <em>Note:</em> The cache must be enabled using
  41. <code>THREE.Cache.enabled = true;</code>
  42. This is a global property and only needs to be set once to be used by all loaders that use FileLoader internally.
  43. [page:Cache Cache] is a cache module that holds the response from each request made through this loader, so each file is requested once.
  44. </p>
  45. <h2>Constructor</h2>
  46. <h3>[name] ( [param:LoadingManager manager] )</h3>
  47. <p>
  48. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
  49. Default is [page:DefaultLoadingManager].
  50. </p>
  51. <h2>Properties</h2>
  52. <p>See the base [page:Loader] class for common properties.</p>
  53. <h3>[property:String mimeType]</h3>
  54. <p>
  55. The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
  56. See [page:.setMimeType]. Default is *undefined*.
  57. </p>
  58. <h3>[property:Object requestHeader]</h3>
  59. <p>The [link:https://developer.mozilla.org/en-US/docs/Glossary/Request_header request header] used in HTTP request. See [page:.setRequestHeader]. Default is *undefined*.</p>
  60. <h3>[property:String responseType]</h3>
  61. <p>The expected response type. See [page:.setResponseType]. Default is *undefined*.</p>
  62. <h3>[property:String withCredentials]</h3>
  63. <p>
  64. Whether the XMLHttpRequest uses credentials. See [page:.setWithCredentials].
  65. Default is *undefined*.
  66. </p>
  67. <h2>Methods</h2>
  68. <p>See the base [page:Loader] class for common methods.</p>
  69. <h3>[method:XMLHttpRequest load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  70. <p>
  71. [page:String url] — the path or URL to the file. This can also be a
  72. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  73. [page:Function onLoad] (optional) — Will be called when loading completes. The argument will be the loaded response.<br />
  74. [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the XMLHttpRequest instance,
  75. which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  76. [page:Function onError] (optional) — Will be called if an error occurs.<br /><br />
  77. Load the URL and pass the response to the onLoad function.
  78. </p>
  79. <h3>[method:FileLoader setMimeType]( [param:String mimeType] )</h3>
  80. <p>
  81. Set the expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType]
  82. of the file being loaded. Note that in many cases this will be determined automatically, so by default it is *undefined*.
  83. </p>
  84. <h3>[method:FileLoader setRequestHeader]( [param:Object requestHeader] )</h3>
  85. <p>
  86. [page:object requestHeader] - key: The name of the header whose value is to be set. value: The value to set as the body of the header.<br /><br />
  87. Set the [link:https://developer.mozilla.org/en-US/docs/Glossary/Request_header request header] used in HTTP request.
  88. </p>
  89. <h3>[method:FileLoader setResponseType]( [param:String responseType] )</h3>
  90. <p>
  91. Change the response type. Valid values are:<br />
  92. [page:String text] or empty string (default) - returns the data as [page:String String].<br />
  93. [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 />
  94. [page:String blob] - returns the data as a [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].<br />
  95. [page:String document] - parses the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
  96. [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 />
  97. </p>
  98. <h3>[method:FileLoader setWithCredentials]( [param:Boolean value] )</h3>
  99. <p>
  100. Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
  101. TLS client certificates. See [link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].<br />
  102. Note that this has no effect if you are loading files locally or from the same domain.
  103. </p>
  104. <h2>Source</h2>
  105. <p>
  106. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  107. </p>
  108. </body>
  109. </html>