FileLoader.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Loader] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. A low level class for loading resources with Fetch, used internally by
  14. most loaders. It can also be used directly to load any file type that does
  15. not have a loader.
  16. </p>
  17. <h2>Code Example</h2>
  18. <code>
  19. const 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. *Note:* 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
  43. loaders that use FileLoader internally. [page:Cache Cache] is a cache
  44. module that holds the response from each request made through this loader,
  45. so each file is requested once.
  46. </p>
  47. <h2>Constructor</h2>
  48. <h3>[name] ( [param:LoadingManager manager] )</h3>
  49. <p>
  50. [page:LoadingManager manager] — The [page:LoadingManager loadingManager]
  51. for the loader to use. Default is [page:DefaultLoadingManager].
  52. </p>
  53. <h2>Properties</h2>
  54. <p>See the base [page:Loader] class for common properties.</p>
  55. <h3>[property:String mimeType]</h3>
  56. <p>
  57. The expected
  58. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType].
  59. See [page:.setMimeType]. Default is `undefined`.
  60. </p>
  61. <h3>[property:String responseType]</h3>
  62. <p>
  63. The expected response type. See [page:.setResponseType]. Default is
  64. `undefined`.
  65. </p>
  66. <h2>Methods</h2>
  67. <p>See the base [page:Loader] class for common methods.</p>
  68. <h3>
  69. [method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
  70. </h3>
  71. <p>
  72. [page:String url] — the path or URL to the file. This can also be a
  73. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  74. [page:Function onLoad] (optional) — Will be called when loading completes.
  75. The argument will be the loaded response.<br />
  76. [page:Function onProgress] (optional) — Will be called while load
  77. progresses. The argument will be the ProgressEvent instance, which
  78. contains .[page:Boolean lengthComputable], .[page:Integer total] and
  79. .[page:Integer loaded]. If the server does not set the Content-Length
  80. header; .[page:Integer total] will be 0.<br />
  81. [page:Function onError] (optional) — Will be called if an error occurs.<br /><br />
  82. Load the URL and pass the response to the onLoad function.
  83. </p>
  84. <h3>[method:this setMimeType]( [param:String mimeType] )</h3>
  85. <p>
  86. Set the expected
  87. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types mimeType]
  88. of the file being loaded. Note that in many cases this will be
  89. determined automatically, so by default it is `undefined`.
  90. </p>
  91. <h3>[method:this setResponseType]( [param:String responseType] )</h3>
  92. <p>
  93. Change the response type. Valid values are:<br />
  94. [page:String text] or empty string (default) - returns the data as
  95. [page:String String].<br />
  96. [page:String arraybuffer] - loads the data into a
  97. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ArrayBuffer] and returns that.<br />
  98. [page:String blob] - returns the data as a
  99. [link:https://developer.mozilla.org/en/docs/Web/API/Blob Blob].<br />
  100. [page:String document] - parses the file using the
  101. [link:https://developer.mozilla.org/en-US/docs/Web/API/DOMParser DOMParser].<br />
  102. [page:String json] - parses the file using
  103. [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse].<br />
  104. </p>
  105. <h2>Source</h2>
  106. <p>
  107. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  108. </p>
  109. </body>
  110. </html>