GLTFLoader.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. <div class="desc"> A loader for loading <em>glTF 2.0</em> resource. <br />
  14. <a href="https://www.khronos.org/gltf">glTF</a> (GL Transmission Format) is an
  15. <a href="https://github.com/KhronosGroup/glTF/tree/master/specification/2.0">open format specification</a>
  16. for efficient delivery and loading of 3D content. Assets may be provided either in JSON (.gltf)
  17. or binary (.glb) format. External files store textures (.jpg, .png, ...) and additional binary
  18. data (.bin). A glTF asset may deliver one or more scenes, including meshes, materials,
  19. textures, skins, skeletons, morph targets, animations, lights, and/or cameras.
  20. </div>
  21. <h2>Extensions</h2>
  22. <div>
  23. GLTFLoader supports the following glTF extensions:
  24. </div>
  25. <ul>
  26. <li>
  27. <a target="_blank" href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness">
  28. KHR_materials_pbrSpecularGlossiness
  29. </a>
  30. </li>
  31. <li>
  32. KHR_lights (experimental)
  33. </li>
  34. </ul>
  35. <h2>Example</h2>
  36. <code>
  37. // Instantiate a loader
  38. var loader = new THREE.GLTFLoader();
  39. // Load a glTF resource
  40. loader.load(
  41. // resource URL
  42. 'models/gltf/duck/duck.gltf',
  43. // called when the resource is loaded
  44. function ( gltf ) {
  45. scene.add( gltf.scene );
  46. gltf.animations; // Array&lt;THREE.AnimationClip&gt;
  47. gltf.scene; // THREE.Scene
  48. gltf.scenes; // Array&lt;THREE.Scene&gt;
  49. gltf.cameras; // Array&lt;THREE.Camera&gt;
  50. },
  51. // called when loading is in progresses
  52. function ( xhr ) {
  53. console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  54. },
  55. // called when loading has errors
  56. function ( error ) {
  57. console.log( 'An error happened' );
  58. }
  59. );
  60. </code>
  61. [example:webgl_loader_gltf]
  62. <h2>Browser compatibility</h2>
  63. <p>GLTFLoader relies on ES6 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a>,
  64. which are not supported in IE11. To use the loader in IE11, you must
  65. <a href="https://github.com/stefanpenner/es6-promise">include a polyfill</a>
  66. providing a Promise replacement.</p>
  67. <br>
  68. <hr>
  69. <h2>Constructor</h2>
  70. <h3>[name]( [page:LoadingManager manager] )</h3>
  71. <div>
  72. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  73. </div>
  74. <div>
  75. Creates a new [name].
  76. </div>
  77. <h2>Properties</h2>
  78. <h2>Methods</h2>
  79. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  80. <div>
  81. [page:String url] — A string containing the path/URL of the <em>.gltf</em> or <em>.glb</em> file.<br />
  82. [page:Function onLoad] — A function to be called after the loading is successfully completed. The function receives the loaded JSON response returned from [page:Function parse].<br />
  83. [page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  84. [page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
  85. </div>
  86. <div>
  87. Begin loading from url and call the callback function with the parsed response content.
  88. </div>
  89. <h3>[method:null setPath]( [page:String path] )</h3>
  90. <div>
  91. [page:String path] — Base path for loading additional resources e.g. textures and .bin data.
  92. </div>
  93. <div>
  94. Set the base path for additional resources.
  95. </div>
  96. <h3>[method:null setCrossOrigin]( [page:String value] )</h3>
  97. <div>
  98. [page:String value] — The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS.
  99. </div>
  100. <h3>[method:null parse]( [page:ArrayBuffer data], [page:String path], [page:Function onLoad], [page:Function onError] )</h3>
  101. <div>
  102. [page:ArrayBuffer data] — glTF asset to parse, as an ArrayBuffer or <em>JSON</em> string.<br />
  103. [page:String path] — The base path from which to find subsequent glTF resources such as textures and .bin data files.<br />
  104. [page:Function onLoad] — A function to be called when parse completes.<br />
  105. [page:Function onError] — (optional) A function to be called if an error occurs during parsing. The function receives error as an argument.<br />
  106. </div>
  107. <div>
  108. Parse a glTF-based ArrayBuffer or <em>JSON</em> String and fire [page:Function onLoad] callback when complete. The argument to [page:Function onLoad] will be an [page:object] that contains loaded parts: .[page:Scene scene], .[page:Array scenes], .[page:Array cameras], and .[page:Array animations].
  109. </div>
  110. <h2>Source</h2>
  111. [link:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js examples/js/loaders/GLTFLoader.js]
  112. </body>
  113. </html>