FileLoader.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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:String responseType]</h3>
  59. <p>The expected response type. See [page:.setResponseType]. Default is *undefined*.</p>
  60. <h3>[property:String withCredentials]</h3>
  61. <p>
  62. Whether the XMLHttpRequest uses credentials. See [page:.setWithCredentials].
  63. Default is *undefined*.
  64. </p>
  65. <h2>Methods</h2>
  66. <p>See the base [page:Loader] class for common methods.</p>
  67. <h3>[method:XMLHttpRequest load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  68. <p>
  69. [page:String url] — the path or URL to the file. This can also be a
  70. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  71. [page:Function onLoad] (optional) — Will be called when loading completes. The argument will be the loaded response.<br />
  72. [page:Function onProgress] (optional) — Will be called while load progresses. The argument will be the XMLHttpRequest instance,
  73. which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  74. [page:Function onError] (optional) — Will be called if an error occurs.<br /><br />
  75. Load the URL and pass the response to the onLoad function.
  76. </p>
  77. <h3>[method:FileLoader setMimeType]( [param:String mimeType] )</h3>
  78. <p>
  79. Set the expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType]
  80. of the file being loaded. Note that in many cases this will be determined automatically, so by default it is *undefined*.
  81. </p>
  82. <h3>[method:FileLoader setResponseType]( [param:String responseType] )</h3>
  83. <p>
  84. Change the response type. Valid values are:<br />
  85. [page:String text] or empty string (default) - returns the data as [page:String String].<br />
  86. [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 />
  87. [page:String blob] - returns the data as a [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].<br />
  88. [page:String document] - parses the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
  89. [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 />
  90. </p>
  91. <h3>[method:FileLoader setWithCredentials]( [param:Boolean value] )</h3>
  92. <p>
  93. Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
  94. TLS client certificates. See [link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].<br />
  95. Note that this has no effect if you are loading files locally or from the same domain.
  96. </p>
  97. <h2>Source</h2>
  98. <p>
  99. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  100. </p>
  101. </body>
  102. </html>