FileLoader.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // Function when resource is loaded
  28. function ( data ) {
  29. // output the text to the console
  30. console.log( data )
  31. },
  32. // Function called when download progresses
  33. function ( xhr ) {
  34. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  35. },
  36. // Function called when download errors
  37. function ( xhr ) {
  38. console.error( 'An error happened' );
  39. } );
  40. </code>
  41. <h2>Constructor</h2>
  42. <h3>[name]( [page:LoadingManager manager] )</h3>
  43. <div>
  44. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use.
  45. Default is [page:DefaultLoadingManager].
  46. </div>
  47. <h2>Properties</h2>
  48. <h3>[property:Cache cache]</h3>
  49. <div>
  50. A reference to [page:Cache Cache] that hold the response from each request made
  51. through this loader, so each file is requested once.<br /><br />
  52. <em>Note:</em>The cache must be enabled using
  53. <code>THREE.Cache.enabled = true.</code>
  54. This is a global property and only needs to be set once to be used by all loaders that use FileLoader internally.
  55. </div>
  56. <h3>[property:String mimeType]</h3>
  57. <div>
  58. The expected [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
  59. See [page:.setMimeType]. Default is *undefined*.
  60. </div>
  61. <h3>[property:String path]</h3>
  62. <div>The base path from which files will be loaded. See [page:.setPath]. Default is *undefined*.</div>
  63. <h3>[property:String responseType]</h3>
  64. <div>The expected response type. See [page:.setResponseType]. Default is *undefined*.</div>
  65. <h3>[property:String withCredentials]</h3>
  66. <div>
  67. Whether the XMLHttpRequest uses credentials such as cookies, authorization headers or
  68. TLS client certificates. See [page:.setWithCredentials] and
  69. [link:https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials XMLHttpRequest.withCredentials].
  70. Default is *undefined*.
  71. </div>
  72. <h2>Methods</h2>
  73. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  74. <div>
  75. [page:String url] — required<br />
  76. [page:Function onLoad] — Will be called when loading completes. The argument will be the loaded response.<br />
  77. [page:Function onProgress] — Will be called while load progresses. The argument will be the XmlHttpRequest instance, that contain .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  78. [page:Function onError] — Will be called if an error occurs.<br /><br />
  79. Begin loading from url and return the [page:String text] response that will contain the data.
  80. </div>
  81. <h3>[method:null setResponseType]( [page:String value] )</h3>
  82. <div>
  83. [page:String value] — the response type. Default is '' (empty string).<br /><br />
  84. Change the response type. Valid values are:<br />
  85. [page:String text], empty string (default), or any other value. Any file type, returns the unprocessed file data.<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] - parse the file using the [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
  89. [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 />
  90. </div>
  91. <h2>Source</h2>
  92. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  93. </body>
  94. </html>