FileLoader.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. <div 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. </div>
  16. <h2>Example</h2>
  17. <div>
  18. [example:webgl_loader_msgpack WebGL / loader / msgpack]<br />
  19. [example:webgl_morphtargets_human WebGL / morphtargets / human]<br />
  20. </div>
  21. <code>
  22. var loader = new THREE.FileLoader();
  23. //load a text file a 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. <h2>Constructor</h2>
  43. <h3>[name]( [page:LoadingManager manager] )</h3>
  44. <div>
  45. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
  46. Default is [page:DefaultLoadingManager].
  47. </div>
  48. <h2>Properties</h2>
  49. <h3>[property:Cache cache]</h3>
  50. <div>
  51. A reference to [page:Cache Cache] that hold the response from each request made
  52. through this loader, so each file is requested once.<br /><br />
  53. <em>Note:</em>The cache must be enabled using
  54. <code>THREE.Cache.enabled = true.</code>
  55. This is a global property and only needs to be set once to be used by all loaders that use FileLoader internally.
  56. </div>
  57. <h3>[property:LoadingManager manager]</h3>
  58. <div>
  59. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  60. </div>
  61. <h3>[property:String mimeType]</h3>
  62. <div>
  63. The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
  64. See [page:.setMimeType]. Default is *undefined*.
  65. </div>
  66. <h3>[property:String path]</h3>
  67. <div>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</div>
  68. <h3>[property:String responseType]</h3>
  69. <div>The expected response type. See [page:.setResponseType]. Default is *undefined*.</div>
  70. <h3>[property:String withCredentials]</h3>
  71. <div>
  72. Whether the XMLHttpRequest uses credentials - see [page:.setWithCredentials].
  73. Default is *undefined*.
  74. </div>
  75. <h2>Methods</h2>
  76. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  77. <div>
  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] — Will be called when loading completes. The argument will be the loaded response.<br />
  81. [page:Function onProgress] — 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] — Will be called if an error occurs.<br /><br />
  84. Load the URL and pass the response to the onLoad function.
  85. </div>
  86. <h3>[method:FileLoader setMimeType]( [page:String mimeType] )</h3>
  87. <div>
  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. </div>
  91. <h3>[method:FileLoader setPath]( [page:String path] )</h3>
  92. <div>
  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. </div>
  96. <h3>[method:FileLoader setResponseType]( [page:String responseType] )</h3>
  97. <div>
  98. [page:String responseType] — Default is '' (empty string).<br /><br />
  99. Change the response type. Valid values are:<br />
  100. [page:String text], empty string (default), or any other value. Any file type, returns the unprocessed file data.<br />
  101. [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 />
  102. [page:String blob] - returns the data as a [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].<br />
  103. [page:String document] - parse the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
  104. [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 />
  105. </div>
  106. <h3>[method:FileLoader setWithCredentials]( [page:Boolean value] )</h3>
  107. Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
  108. TLS client certificates. See
  109. [link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].<br />
  110. Note that this has no effect if you are loading files locally or from the same domain.
  111. <div>
  112. </div>
  113. <h2>Source</h2>
  114. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  115. </body>
  116. </html>