class_gltfdocument.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/modules/gltf/doc_classes/GLTFDocument.xml.
  6. .. _class_GLTFDocument:
  7. GLTFDocument
  8. ============
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Class for importing and exporting glTF files in and out of Godot.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. GLTFDocument supports reading data from a glTF file, buffer, or Godot scene. This data can then be written to the filesystem, buffer, or used to create a Godot scene.
  15. All of the data in a GLTF scene is stored in the :ref:`GLTFState<class_GLTFState>` class. GLTFDocument processes state objects, but does not contain any scene data itself. GLTFDocument has member variables to store export configuration settings such as the image format, but is otherwise stateless. Multiple scenes can be processed with the same settings using the same GLTFDocument object and different :ref:`GLTFState<class_GLTFState>` objects.
  16. GLTFDocument can be extended with arbitrary functionality by extending the :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` class and registering it with GLTFDocument via :ref:`register_gltf_document_extension<class_GLTFDocument_method_register_gltf_document_extension>`. This allows for custom data to be imported and exported.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - `glTF 'What the duck?' guide <https://www.khronos.org/files/gltf20-reference-guide.pdf>`__
  21. - `Khronos glTF specification <https://registry.khronos.org/glTF/>`__
  22. .. rst-class:: classref-reftable-group
  23. Properties
  24. ----------
  25. .. table::
  26. :widths: auto
  27. +-----------------------------------------------------+-------------------------------------------------------------------+-----------+
  28. | :ref:`String<class_String>` | :ref:`image_format<class_GLTFDocument_property_image_format>` | ``"PNG"`` |
  29. +-----------------------------------------------------+-------------------------------------------------------------------+-----------+
  30. | :ref:`float<class_float>` | :ref:`lossy_quality<class_GLTFDocument_property_lossy_quality>` | ``0.75`` |
  31. +-----------------------------------------------------+-------------------------------------------------------------------+-----------+
  32. | :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` | :ref:`root_node_mode<class_GLTFDocument_property_root_node_mode>` | ``0`` |
  33. +-----------------------------------------------------+-------------------------------------------------------------------+-----------+
  34. .. rst-class:: classref-reftable-group
  35. Methods
  36. -------
  37. .. table::
  38. :widths: auto
  39. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`append_from_buffer<class_GLTFDocument_method_append_from_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` bytes, :ref:`String<class_String>` base_path, :ref:`GLTFState<class_GLTFState>` state, :ref:`int<class_int>` flags=0 **)** |
  41. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`append_from_file<class_GLTFDocument_method_append_from_file>` **(** :ref:`String<class_String>` path, :ref:`GLTFState<class_GLTFState>` state, :ref:`int<class_int>` flags=0, :ref:`String<class_String>` base_path="" **)** |
  43. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`append_from_scene<class_GLTFDocument_method_append_from_scene>` **(** :ref:`Node<class_Node>` node, :ref:`GLTFState<class_GLTFState>` state, :ref:`int<class_int>` flags=0 **)** |
  45. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`generate_buffer<class_GLTFDocument_method_generate_buffer>` **(** :ref:`GLTFState<class_GLTFState>` state **)** |
  47. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Node<class_Node>` | :ref:`generate_scene<class_GLTFDocument_method_generate_scene>` **(** :ref:`GLTFState<class_GLTFState>` state, :ref:`float<class_float>` bake_fps=30, :ref:`bool<class_bool>` trimming=false, :ref:`bool<class_bool>` remove_immutable_tracks=true **)** |
  49. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`register_gltf_document_extension<class_GLTFDocument_method_register_gltf_document_extension>` **(** :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` extension, :ref:`bool<class_bool>` first_priority=false **)** |static| |
  51. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`unregister_gltf_document_extension<class_GLTFDocument_method_unregister_gltf_document_extension>` **(** :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` extension **)** |static| |
  53. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`write_to_filesystem<class_GLTFDocument_method_write_to_filesystem>` **(** :ref:`GLTFState<class_GLTFState>` state, :ref:`String<class_String>` path **)** |
  55. +-----------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. .. rst-class:: classref-section-separator
  57. ----
  58. .. rst-class:: classref-descriptions-group
  59. Enumerations
  60. ------------
  61. .. _enum_GLTFDocument_RootNodeMode:
  62. .. rst-class:: classref-enumeration
  63. enum **RootNodeMode**:
  64. .. _class_GLTFDocument_constant_ROOT_NODE_MODE_SINGLE_ROOT:
  65. .. rst-class:: classref-enumeration-constant
  66. :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` **ROOT_NODE_MODE_SINGLE_ROOT** = ``0``
  67. Treat the Godot scene's root node as the root node of the glTF file, and mark it as the single root node via the ``GODOT_single_root`` glTF extension. This will be parsed the same as :ref:`ROOT_NODE_MODE_KEEP_ROOT<class_GLTFDocument_constant_ROOT_NODE_MODE_KEEP_ROOT>` if the implementation does not support ``GODOT_single_root``.
  68. .. _class_GLTFDocument_constant_ROOT_NODE_MODE_KEEP_ROOT:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` **ROOT_NODE_MODE_KEEP_ROOT** = ``1``
  71. Treat the Godot scene's root node as the root node of the glTF file, but do not mark it as anything special. An extra root node will be generated when importing into Godot. This uses only vanilla glTF features. This is equivalent to the behavior in Godot 4.1 and earlier.
  72. .. _class_GLTFDocument_constant_ROOT_NODE_MODE_MULTI_ROOT:
  73. .. rst-class:: classref-enumeration-constant
  74. :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` **ROOT_NODE_MODE_MULTI_ROOT** = ``2``
  75. Treat the Godot scene's root node as the name of the glTF scene, and add all of its children as root nodes of the glTF file. This uses only vanilla glTF features. This avoids an extra root node, but only the name of the Godot scene's root node will be preserved, as it will not be saved as a node.
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Property Descriptions
  80. ---------------------
  81. .. _class_GLTFDocument_property_image_format:
  82. .. rst-class:: classref-property
  83. :ref:`String<class_String>` **image_format** = ``"PNG"``
  84. .. rst-class:: classref-property-setget
  85. - void **set_image_format** **(** :ref:`String<class_String>` value **)**
  86. - :ref:`String<class_String>` **get_image_format** **(** **)**
  87. The user-friendly name of the export image format. This is used when exporting the GLTF file, including writing to a file and writing to a byte array.
  88. By default, Godot allows the following options: "None", "PNG", "JPEG", "Lossless WebP", and "Lossy WebP". Support for more image formats can be added in :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` classes.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_GLTFDocument_property_lossy_quality:
  92. .. rst-class:: classref-property
  93. :ref:`float<class_float>` **lossy_quality** = ``0.75``
  94. .. rst-class:: classref-property-setget
  95. - void **set_lossy_quality** **(** :ref:`float<class_float>` value **)**
  96. - :ref:`float<class_float>` **get_lossy_quality** **(** **)**
  97. If :ref:`image_format<class_GLTFDocument_property_image_format>` is a lossy image format, this determines the lossy quality of the image. On a range of ``0.0`` to ``1.0``, where ``0.0`` is the lowest quality and ``1.0`` is the highest quality. A lossy quality of ``1.0`` is not the same as lossless.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_GLTFDocument_property_root_node_mode:
  101. .. rst-class:: classref-property
  102. :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` **root_node_mode** = ``0``
  103. .. rst-class:: classref-property-setget
  104. - void **set_root_node_mode** **(** :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` value **)**
  105. - :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` **get_root_node_mode** **(** **)**
  106. How to process the root node during export. See :ref:`RootNodeMode<enum_GLTFDocument_RootNodeMode>` for details. The default and recommended value is :ref:`ROOT_NODE_MODE_SINGLE_ROOT<class_GLTFDocument_constant_ROOT_NODE_MODE_SINGLE_ROOT>`.
  107. \ **Note:** Regardless of how the glTF file is exported, when importing, the root node type and name can be overridden in the scene import settings tab.
  108. .. rst-class:: classref-section-separator
  109. ----
  110. .. rst-class:: classref-descriptions-group
  111. Method Descriptions
  112. -------------------
  113. .. _class_GLTFDocument_method_append_from_buffer:
  114. .. rst-class:: classref-method
  115. :ref:`Error<enum_@GlobalScope_Error>` **append_from_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` bytes, :ref:`String<class_String>` base_path, :ref:`GLTFState<class_GLTFState>` state, :ref:`int<class_int>` flags=0 **)**
  116. Takes a :ref:`PackedByteArray<class_PackedByteArray>` defining a GLTF and imports the data to the given :ref:`GLTFState<class_GLTFState>` object through the ``state`` parameter.
  117. \ **Note:** The ``base_path`` tells :ref:`append_from_buffer<class_GLTFDocument_method_append_from_buffer>` where to find dependencies and can be empty.
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _class_GLTFDocument_method_append_from_file:
  121. .. rst-class:: classref-method
  122. :ref:`Error<enum_@GlobalScope_Error>` **append_from_file** **(** :ref:`String<class_String>` path, :ref:`GLTFState<class_GLTFState>` state, :ref:`int<class_int>` flags=0, :ref:`String<class_String>` base_path="" **)**
  123. Takes a path to a GLTF file and imports the data at that file path to the given :ref:`GLTFState<class_GLTFState>` object through the ``state`` parameter.
  124. \ **Note:** The ``base_path`` tells :ref:`append_from_file<class_GLTFDocument_method_append_from_file>` where to find dependencies and can be empty.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_GLTFDocument_method_append_from_scene:
  128. .. rst-class:: classref-method
  129. :ref:`Error<enum_@GlobalScope_Error>` **append_from_scene** **(** :ref:`Node<class_Node>` node, :ref:`GLTFState<class_GLTFState>` state, :ref:`int<class_int>` flags=0 **)**
  130. Takes a Godot Engine scene node and exports it and its descendants to the given :ref:`GLTFState<class_GLTFState>` object through the ``state`` parameter.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_GLTFDocument_method_generate_buffer:
  134. .. rst-class:: classref-method
  135. :ref:`PackedByteArray<class_PackedByteArray>` **generate_buffer** **(** :ref:`GLTFState<class_GLTFState>` state **)**
  136. Takes a :ref:`GLTFState<class_GLTFState>` object through the ``state`` parameter and returns a GLTF :ref:`PackedByteArray<class_PackedByteArray>`.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_GLTFDocument_method_generate_scene:
  140. .. rst-class:: classref-method
  141. :ref:`Node<class_Node>` **generate_scene** **(** :ref:`GLTFState<class_GLTFState>` state, :ref:`float<class_float>` bake_fps=30, :ref:`bool<class_bool>` trimming=false, :ref:`bool<class_bool>` remove_immutable_tracks=true **)**
  142. Takes a :ref:`GLTFState<class_GLTFState>` object through the ``state`` parameter and returns a Godot Engine scene node.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_GLTFDocument_method_register_gltf_document_extension:
  146. .. rst-class:: classref-method
  147. void **register_gltf_document_extension** **(** :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` extension, :ref:`bool<class_bool>` first_priority=false **)** |static|
  148. Registers the given :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` instance with GLTFDocument. If ``first_priority`` is true, this extension will be run first. Otherwise, it will be run last.
  149. \ **Note:** Like GLTFDocument itself, all GLTFDocumentExtension classes must be stateless in order to function properly. If you need to store data, use the ``set_additional_data`` and ``get_additional_data`` methods in :ref:`GLTFState<class_GLTFState>` or :ref:`GLTFNode<class_GLTFNode>`.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_GLTFDocument_method_unregister_gltf_document_extension:
  153. .. rst-class:: classref-method
  154. void **unregister_gltf_document_extension** **(** :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` extension **)** |static|
  155. Unregisters the given :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>` instance.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_GLTFDocument_method_write_to_filesystem:
  159. .. rst-class:: classref-method
  160. :ref:`Error<enum_@GlobalScope_Error>` **write_to_filesystem** **(** :ref:`GLTFState<class_GLTFState>` state, :ref:`String<class_String>` path **)**
  161. Takes a :ref:`GLTFState<class_GLTFState>` object through the ``state`` parameter and writes a glTF file to the filesystem.
  162. \ **Note:** The extension of the glTF file determines if it is a .glb binary file or a .gltf file.
  163. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  164. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  165. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  166. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  167. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  168. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  169. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`