FileLoader.html 5.8 KB

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