Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/doc_classes/GLTFDocument.xml
10279 views
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<class name="GLTFDocument" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3
<brief_description>
4
Class for importing and exporting glTF files in and out of Godot.
5
</brief_description>
6
<description>
7
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.
8
All of the data in a glTF scene is stored in the [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 [GLTFState] objects.
9
GLTFDocument can be extended with arbitrary functionality by extending the [GLTFDocumentExtension] class and registering it with GLTFDocument via [method register_gltf_document_extension]. This allows for custom data to be imported and exported.
10
</description>
11
<tutorials>
12
<link title="Runtime file loading and saving">$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html</link>
13
<link title="glTF &apos;What the duck?&apos; guide">https://www.khronos.org/files/gltf20-reference-guide.pdf</link>
14
<link title="Khronos glTF specification">https://registry.khronos.org/glTF/</link>
15
</tutorials>
16
<methods>
17
<method name="append_from_buffer">
18
<return type="int" enum="Error" />
19
<param index="0" name="bytes" type="PackedByteArray" />
20
<param index="1" name="base_path" type="String" />
21
<param index="2" name="state" type="GLTFState" />
22
<param index="3" name="flags" type="int" default="0" />
23
<description>
24
Takes a [PackedByteArray] defining a glTF and imports the data to the given [GLTFState] object through the [param state] parameter.
25
[b]Note:[/b] The [param base_path] tells [method append_from_buffer] where to find dependencies and can be empty.
26
</description>
27
</method>
28
<method name="append_from_file">
29
<return type="int" enum="Error" />
30
<param index="0" name="path" type="String" />
31
<param index="1" name="state" type="GLTFState" />
32
<param index="2" name="flags" type="int" default="0" />
33
<param index="3" name="base_path" type="String" default="&quot;&quot;" />
34
<description>
35
Takes a path to a glTF file and imports the data at that file path to the given [GLTFState] object through the [param state] parameter.
36
[b]Note:[/b] The [param base_path] tells [method append_from_file] where to find dependencies and can be empty.
37
</description>
38
</method>
39
<method name="append_from_scene">
40
<return type="int" enum="Error" />
41
<param index="0" name="node" type="Node" />
42
<param index="1" name="state" type="GLTFState" />
43
<param index="2" name="flags" type="int" default="0" />
44
<description>
45
Takes a Godot Engine scene node and exports it and its descendants to the given [GLTFState] object through the [param state] parameter.
46
</description>
47
</method>
48
<method name="export_object_model_property" qualifiers="static">
49
<return type="GLTFObjectModelProperty" />
50
<param index="0" name="state" type="GLTFState" />
51
<param index="1" name="node_path" type="NodePath" />
52
<param index="2" name="godot_node" type="Node" />
53
<param index="3" name="gltf_node_index" type="int" />
54
<description>
55
Determines a mapping between the given Godot [param node_path] and the corresponding glTF Object Model JSON pointer(s) in the generated glTF file. The details of this mapping are returned in a [GLTFObjectModelProperty] object. Additional mappings can be supplied via the [method GLTFDocumentExtension._import_object_model_property] callback method.
56
</description>
57
</method>
58
<method name="generate_buffer">
59
<return type="PackedByteArray" />
60
<param index="0" name="state" type="GLTFState" />
61
<description>
62
Takes a [GLTFState] object through the [param state] parameter and returns a glTF [PackedByteArray].
63
</description>
64
</method>
65
<method name="generate_scene">
66
<return type="Node" />
67
<param index="0" name="state" type="GLTFState" />
68
<param index="1" name="bake_fps" type="float" default="30" />
69
<param index="2" name="trimming" type="bool" default="false" />
70
<param index="3" name="remove_immutable_tracks" type="bool" default="true" />
71
<description>
72
Takes a [GLTFState] object through the [param state] parameter and returns a Godot Engine scene node.
73
The [param bake_fps] parameter overrides the bake_fps in [param state].
74
</description>
75
</method>
76
<method name="get_supported_gltf_extensions" qualifiers="static">
77
<return type="PackedStringArray" />
78
<description>
79
Returns a list of all support glTF extensions, including extensions supported directly by the engine, and extensions supported by user plugins registering [GLTFDocumentExtension] classes.
80
[b]Note:[/b] If this method is run before a GLTFDocumentExtension is registered, its extensions won't be included in the list. Be sure to only run this method after all extensions are registered. If you run this when the engine starts, consider waiting a frame before calling this method to ensure all extensions are registered.
81
</description>
82
</method>
83
<method name="import_object_model_property" qualifiers="static">
84
<return type="GLTFObjectModelProperty" />
85
<param index="0" name="state" type="GLTFState" />
86
<param index="1" name="json_pointer" type="String" />
87
<description>
88
Determines a mapping between the given glTF Object Model [param json_pointer] and the corresponding Godot node path(s) in the generated Godot scene. The details of this mapping are returned in a [GLTFObjectModelProperty] object. Additional mappings can be supplied via the [method GLTFDocumentExtension._export_object_model_property] callback method.
89
</description>
90
</method>
91
<method name="register_gltf_document_extension" qualifiers="static">
92
<return type="void" />
93
<param index="0" name="extension" type="GLTFDocumentExtension" />
94
<param index="1" name="first_priority" type="bool" default="false" />
95
<description>
96
Registers the given [GLTFDocumentExtension] instance with GLTFDocument. If [param first_priority] is [code]true[/code], this extension will be run first. Otherwise, it will be run last.
97
[b]Note:[/b] Like GLTFDocument itself, all GLTFDocumentExtension classes must be stateless in order to function properly. If you need to store data, use the [code]set_additional_data[/code] and [code]get_additional_data[/code] methods in [GLTFState] or [GLTFNode].
98
</description>
99
</method>
100
<method name="unregister_gltf_document_extension" qualifiers="static">
101
<return type="void" />
102
<param index="0" name="extension" type="GLTFDocumentExtension" />
103
<description>
104
Unregisters the given [GLTFDocumentExtension] instance.
105
</description>
106
</method>
107
<method name="write_to_filesystem">
108
<return type="int" enum="Error" />
109
<param index="0" name="state" type="GLTFState" />
110
<param index="1" name="path" type="String" />
111
<description>
112
Takes a [GLTFState] object through the [param state] parameter and writes a glTF file to the filesystem.
113
[b]Note:[/b] The extension of the glTF file determines if it is a .glb binary file or a .gltf text file.
114
</description>
115
</method>
116
</methods>
117
<members>
118
<member name="fallback_image_format" type="String" setter="set_fallback_image_format" getter="get_fallback_image_format" default="&quot;None&quot;">
119
The user-friendly name of the fallback image format. This is used when exporting the glTF file, including writing to a file and writing to a byte array.
120
This property may only be one of "None", "PNG", or "JPEG", and is only used when the [member image_format] is not one of "None", "PNG", or "JPEG". If having multiple extension image formats is desired, that can be done using a [GLTFDocumentExtension] class - this property only covers the use case of providing a base glTF fallback image when using a custom image format.
121
</member>
122
<member name="fallback_image_quality" type="float" setter="set_fallback_image_quality" getter="get_fallback_image_quality" default="0.25">
123
The quality of the fallback image, if any. For PNG files, this downscales the image on both dimensions by this factor. For JPEG files, this is the lossy quality of the image. A low value is recommended, since including multiple high quality images in a glTF file defeats the file size gains of using a more efficient image format.
124
</member>
125
<member name="image_format" type="String" setter="set_image_format" getter="get_image_format" default="&quot;PNG&quot;">
126
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.
127
By default, Godot allows the following options: "None", "PNG", "JPEG", "Lossless WebP", and "Lossy WebP". Support for more image formats can be added in [GLTFDocumentExtension] classes. A single extension class can provide multiple options for the specific format to use, or even an option that uses multiple formats at once.
128
</member>
129
<member name="lossy_quality" type="float" setter="set_lossy_quality" getter="get_lossy_quality" default="0.75">
130
If [member image_format] is a lossy image format, this determines the lossy quality of the image. On a range of [code]0.0[/code] to [code]1.0[/code], where [code]0.0[/code] is the lowest quality and [code]1.0[/code] is the highest quality. A lossy quality of [code]1.0[/code] is not the same as lossless.
131
</member>
132
<member name="root_node_mode" type="int" setter="set_root_node_mode" getter="get_root_node_mode" enum="GLTFDocument.RootNodeMode" default="0">
133
How to process the root node during export. The default and recommended value is [constant ROOT_NODE_MODE_SINGLE_ROOT].
134
[b]Note:[/b] 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.
135
</member>
136
<member name="visibility_mode" type="int" setter="set_visibility_mode" getter="get_visibility_mode" enum="GLTFDocument.VisibilityMode" default="0">
137
How to deal with node visibility during export. This setting does nothing if all nodes are visible. The default and recommended value is [constant VISIBILITY_MODE_INCLUDE_REQUIRED], which uses the [code]KHR_node_visibility[/code] extension.
138
</member>
139
</members>
140
<constants>
141
<constant name="ROOT_NODE_MODE_SINGLE_ROOT" value="0" enum="RootNodeMode">
142
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 [code]GODOT_single_root[/code] glTF extension. This will be parsed the same as [constant ROOT_NODE_MODE_KEEP_ROOT] if the implementation does not support [code]GODOT_single_root[/code].
143
</constant>
144
<constant name="ROOT_NODE_MODE_KEEP_ROOT" value="1" enum="RootNodeMode">
145
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.
146
</constant>
147
<constant name="ROOT_NODE_MODE_MULTI_ROOT" value="2" enum="RootNodeMode">
148
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.
149
</constant>
150
<constant name="VISIBILITY_MODE_INCLUDE_REQUIRED" value="0" enum="VisibilityMode">
151
If the scene contains any non-visible nodes, include them, mark them as non-visible with [code]KHR_node_visibility[/code], and require that importers respect their non-visibility. Downside: If the importer does not support [code]KHR_node_visibility[/code], the file cannot be imported.
152
</constant>
153
<constant name="VISIBILITY_MODE_INCLUDE_OPTIONAL" value="1" enum="VisibilityMode">
154
If the scene contains any non-visible nodes, include them, mark them as non-visible with [code]KHR_node_visibility[/code], and do not impose any requirements on importers. Downside: If the importer does not support [code]KHR_node_visibility[/code], invisible objects will be visible.
155
</constant>
156
<constant name="VISIBILITY_MODE_EXCLUDE" value="2" enum="VisibilityMode">
157
If the scene contains any non-visible nodes, do not include them in the export. This is the same as the behavior in Godot 4.4 and earlier. Downside: Invisible nodes will not exist in the exported file.
158
</constant>
159
</constants>
160
</class>
161
162