GLTFExporter.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. <h1>[name]</h1>
  11. <p class="desc">
  12. An exporter for `glTF` 2.0.
  13. <br /><br />
  14. [link:https://www.khronos.org/gltf glTF] (GL Transmission Format) is an
  15. [link:https://github.com/KhronosGroup/glTF/tree/master/specification/2.0 open format specification]
  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. </p>
  21. <h2>Import</h2>
  22. <p>
  23. [name] is an add-on, and must be imported explicitly.
  24. See [link:#manual/introduction/Installation Installation / Addons].
  25. </p>
  26. <code>
  27. import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
  28. </code>
  29. <h2>Extensions</h2>
  30. <p>
  31. GLTFExporter supports the following
  32. [link:https://github.com/KhronosGroup/glTF/tree/master/extensions/ glTF 2.0 extensions]:
  33. </p>
  34. <ul>
  35. <li>KHR_lights_punctual</li>
  36. <li>KHR_materials_clearcoat</li>
  37. <li>KHR_materials_emissive_strength</li>
  38. <li>KHR_materials_ior</li>
  39. <li>KHR_materials_iridescence</li>
  40. <li>KHR_materials_specular</li>
  41. <li>KHR_materials_sheen</li>
  42. <li>KHR_materials_transmission</li>
  43. <li>KHR_materials_unlit</li>
  44. <li>KHR_materials_volume</li>
  45. <li>KHR_mesh_quantization</li>
  46. <li>KHR_texture_transform</li>
  47. </ul>
  48. <p>
  49. The following glTF 2.0 extension is supported by an external user plugin
  50. </p>
  51. <ul>
  52. <li>[link:https://github.com/takahirox/three-gltf-extensions KHR_materials_variants]</li>
  53. </ul>
  54. <h2>Code Example</h2>
  55. <code>
  56. // Instantiate a exporter
  57. const exporter = new GLTFExporter();
  58. // Parse the input and generate the glTF output
  59. exporter.parse(
  60. scene,
  61. // called when the gltf has been generated
  62. function ( gltf ) {
  63. console.log( gltf );
  64. downloadJSON( gltf );
  65. },
  66. // called when there is an error in the generation
  67. function ( error ) {
  68. console.log( 'An error happened' );
  69. },
  70. options
  71. );
  72. </code>
  73. <h2>Examples</h2>
  74. <p>
  75. [example:misc_exporter_gltf]
  76. </p>
  77. <h2>Constructor</h2>
  78. <h3>[name]()</h3>
  79. <p>
  80. </p>
  81. <p>
  82. Creates a new [name].
  83. </p>
  84. <h2>Methods</h2>
  85. <h3>[method:undefined parse]( [param:Object3D input], [param:Function onCompleted], [param:Function onError], [param:Object options] )</h3>
  86. <p>
  87. [page:Object input] — Scenes or objects to export. Valid options:<br />
  88. <ul>
  89. <li>
  90. Export scenes
  91. <code>
  92. exporter.parse( scene1, ... )
  93. exporter.parse( [ scene1, scene2 ], ... )
  94. </code>
  95. </li>
  96. <li>
  97. Export objects (It will create a new Scene to hold all the objects)
  98. <code>
  99. exporter.parse( object1, ... )
  100. exporter.parse( [ object1, object2 ], ... )
  101. </code>
  102. </li>
  103. <li>
  104. Mix scenes and objects (It will export the scenes as usual but it will create a new scene to hold all the single objects).
  105. <code>
  106. exporter.parse( [ scene1, object1, object2, scene2 ], ... )
  107. </code>
  108. </li>
  109. </ul>
  110. [page:Function onCompleted] — Will be called when the export completes. The argument will be the generated glTF JSON or binary ArrayBuffer.<br />
  111. [page:Function onError] — Will be called if there are any errors during the gltf generation.<br />
  112. [page:Options options] — Export options<br />
  113. <ul>
  114. <li>trs - bool. Export position, rotation and scale instead of matrix per node. Default is false</li>
  115. <li>onlyVisible - bool. Export only visible objects. Default is true.</li>
  116. <li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
  117. <li>maxTextureSize - int. Restricts the image maximum size (both width and height) to the given value. Default is Infinity.</li>
  118. <li>animations - Array<[page:AnimationClip AnimationClip]>. List of animations to be included in the export.</li>
  119. <li>includeCustomExtensions - bool. Export custom glTF extensions defined on an object's `userData.gltfExtensions` property. Default is false.</li>
  120. </ul>
  121. </p>
  122. <p>
  123. Generates a .gltf (JSON) or .glb (binary) output from the input (Scenes or Objects)
  124. </p>
  125. <h2>Source</h2>
  126. <p>
  127. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/exporters/GLTFExporter.js examples/jsm/exporters/GLTFExporter.js]
  128. </p>
  129. </body>
  130. </html>