186 lines
17 KiB
XML
186 lines
17 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<class name="GLTFDocument" inherits="Resource" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
|
|
<brief_description>
|
|
Class for importing and exporting glTF files in and out of Godot.
|
|
</brief_description>
|
|
<description>
|
|
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.
|
|
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.
|
|
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.
|
|
</description>
|
|
<tutorials>
|
|
<link title="Runtime file loading and saving">$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html</link>
|
|
<link title="glTF 'What the duck?' guide">https://www.khronos.org/files/gltf20-reference-guide.pdf</link>
|
|
<link title="Khronos glTF specification">https://registry.khronos.org/glTF/</link>
|
|
</tutorials>
|
|
<methods>
|
|
<method name="append_from_buffer">
|
|
<return type="int" enum="Error" />
|
|
<param index="0" name="bytes" type="PackedByteArray" />
|
|
<param index="1" name="base_path" type="String" />
|
|
<param index="2" name="state" type="GLTFState" />
|
|
<param index="3" name="flags" type="int" default="0" />
|
|
<description>
|
|
Takes a [PackedByteArray] defining a glTF and imports the data to the given [GLTFState] object through the [param state] parameter.
|
|
[b]Note:[/b] The [param base_path] tells [method append_from_buffer] where to find dependencies and can be empty.
|
|
</description>
|
|
</method>
|
|
<method name="append_from_file">
|
|
<return type="int" enum="Error" />
|
|
<param index="0" name="path" type="String" />
|
|
<param index="1" name="state" type="GLTFState" />
|
|
<param index="2" name="flags" type="int" default="0" />
|
|
<param index="3" name="base_path" type="String" default="""" />
|
|
<description>
|
|
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.
|
|
[b]Note:[/b] The [param base_path] tells [method append_from_file] where to find dependencies and can be empty.
|
|
</description>
|
|
</method>
|
|
<method name="append_from_scene">
|
|
<return type="int" enum="Error" />
|
|
<param index="0" name="node" type="Node" />
|
|
<param index="1" name="state" type="GLTFState" />
|
|
<param index="2" name="flags" type="int" default="0" />
|
|
<description>
|
|
Takes a Godot Engine scene node and exports it and its descendants to the given [GLTFState] object through the [param state] parameter.
|
|
</description>
|
|
</method>
|
|
<method name="export_object_model_property" qualifiers="static">
|
|
<return type="GLTFObjectModelProperty" />
|
|
<param index="0" name="state" type="GLTFState" />
|
|
<param index="1" name="node_path" type="NodePath" />
|
|
<param index="2" name="godot_node" type="Node" />
|
|
<param index="3" name="gltf_node_index" type="int" />
|
|
<description>
|
|
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.
|
|
</description>
|
|
</method>
|
|
<method name="generate_buffer">
|
|
<return type="PackedByteArray" />
|
|
<param index="0" name="state" type="GLTFState" />
|
|
<description>
|
|
Takes a [GLTFState] object through the [param state] parameter and returns a glTF [PackedByteArray].
|
|
</description>
|
|
</method>
|
|
<method name="generate_scene">
|
|
<return type="Node" />
|
|
<param index="0" name="state" type="GLTFState" />
|
|
<param index="1" name="bake_fps" type="float" default="30" />
|
|
<param index="2" name="trimming" type="bool" default="false" />
|
|
<param index="3" name="remove_immutable_tracks" type="bool" default="true" />
|
|
<description>
|
|
Takes a [GLTFState] object through the [param state] parameter and returns a Godot Engine scene node.
|
|
The [param bake_fps] parameter overrides the bake_fps in [param state].
|
|
</description>
|
|
</method>
|
|
<method name="get_supported_gltf_extensions" qualifiers="static">
|
|
<return type="PackedStringArray" />
|
|
<description>
|
|
Returns a list of all support glTF extensions, including extensions supported directly by the engine, and extensions supported by user plugins registering [GLTFDocumentExtension] classes.
|
|
[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.
|
|
</description>
|
|
</method>
|
|
<method name="import_object_model_property" qualifiers="static">
|
|
<return type="GLTFObjectModelProperty" />
|
|
<param index="0" name="state" type="GLTFState" />
|
|
<param index="1" name="json_pointer" type="String" />
|
|
<description>
|
|
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.
|
|
</description>
|
|
</method>
|
|
<method name="register_gltf_document_extension" qualifiers="static">
|
|
<return type="void" />
|
|
<param index="0" name="extension" type="GLTFDocumentExtension" />
|
|
<param index="1" name="first_priority" type="bool" default="false" />
|
|
<description>
|
|
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.
|
|
[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].
|
|
</description>
|
|
</method>
|
|
<method name="unregister_gltf_document_extension" qualifiers="static">
|
|
<return type="void" />
|
|
<param index="0" name="extension" type="GLTFDocumentExtension" />
|
|
<description>
|
|
Unregisters the given [GLTFDocumentExtension] instance.
|
|
</description>
|
|
</method>
|
|
<method name="write_to_filesystem">
|
|
<return type="int" enum="Error" />
|
|
<param index="0" name="state" type="GLTFState" />
|
|
<param index="1" name="path" type="String" />
|
|
<description>
|
|
Takes a [GLTFState] object through the [param state] parameter and writes a glTF file to the filesystem.
|
|
[b]Note:[/b] The extension of the glTF file determines if it is a .glb binary file or a .gltf text file.
|
|
</description>
|
|
</method>
|
|
</methods>
|
|
<members>
|
|
<member name="fallback_image_format" type="String" setter="set_fallback_image_format" getter="get_fallback_image_format" default=""None"">
|
|
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.
|
|
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.
|
|
</member>
|
|
<member name="fallback_image_quality" type="float" setter="set_fallback_image_quality" getter="get_fallback_image_quality" default="0.25">
|
|
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.
|
|
</member>
|
|
<member name="image_format" type="String" setter="set_image_format" getter="get_image_format" default=""PNG"">
|
|
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.
|
|
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.
|
|
</member>
|
|
<member name="lossy_quality" type="float" setter="set_lossy_quality" getter="get_lossy_quality" default="0.75">
|
|
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.
|
|
</member>
|
|
<member name="root_node_mode" type="int" setter="set_root_node_mode" getter="get_root_node_mode" enum="GLTFDocument.RootNodeMode" default="0">
|
|
How to process the root node during export. The default and recommended value is [constant ROOT_NODE_MODE_SINGLE_ROOT].
|
|
[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.
|
|
</member>
|
|
<member name="texture_map_mode" type="int" setter="set_texture_map_mode" getter="get_texture_map_mode" enum="GLTFDocument.TextureMapMode" default="1">
|
|
How to handle texture maps during import. The default and recommended value is [constant TEXTURE_MAP_MODE_REMAP_TO_STANDARD_MATERIAL], which automatically remaps from glTF's flexible texture map system to the more specific texture map slots in Godot's [StandardMaterial3D] class. Alternatively, [constant TEXTURE_MAP_MODE_DO_NOT_REMAP] can be used to preserve the original texture maps from the glTF file, which may be desirable if using the glTF file with custom shaders, but may not display correctly with Godot's built-in materials.
|
|
</member>
|
|
<member name="visibility_mode" type="int" setter="set_visibility_mode" getter="get_visibility_mode" enum="GLTFDocument.VisibilityMode" default="0">
|
|
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.
|
|
</member>
|
|
</members>
|
|
<constants>
|
|
<constant name="ROOT_NODE_MODE_SINGLE_ROOT" value="0" enum="RootNodeMode">
|
|
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].
|
|
</constant>
|
|
<constant name="ROOT_NODE_MODE_KEEP_ROOT" value="1" enum="RootNodeMode">
|
|
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.
|
|
</constant>
|
|
<constant name="ROOT_NODE_MODE_MULTI_ROOT" value="2" enum="RootNodeMode">
|
|
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.
|
|
</constant>
|
|
<constant name="TEXTURE_MAP_MODE_DO_NOT_REMAP" value="0" enum="TextureMapMode">
|
|
Import the texture maps in the glTF file as they are, without trying to fit them into specific texture slots suitable for Godot's built-in materials. This may be desirable if using the glTF file with custom shaders, but may not display correctly with Godot's built-in materials. This is equivalent to the behavior in Godot 4.6 and earlier.
|
|
</constant>
|
|
<constant name="TEXTURE_MAP_MODE_REMAP_TO_STANDARD_MATERIAL" value="1" enum="TextureMapMode">
|
|
Import the texture maps in the glTF file remapped to the most suitable texture slots based on Godot's [StandardMaterial3D] class. This is the default behavior.
|
|
</constant>
|
|
<constant name="VISIBILITY_MODE_INCLUDE_REQUIRED" value="0" enum="VisibilityMode">
|
|
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.
|
|
</constant>
|
|
<constant name="VISIBILITY_MODE_INCLUDE_OPTIONAL" value="1" enum="VisibilityMode">
|
|
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.
|
|
</constant>
|
|
<constant name="VISIBILITY_MODE_EXCLUDE" value="2" enum="VisibilityMode">
|
|
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.
|
|
</constant>
|
|
<constant name="IMPORT_FLAG_GENERATE_TANGENT_ARRAYS" value="8" enum="ImportFlags" is_bitfield="true">
|
|
If [code]true[/code], generate vertex tangents using [url=http://www.mikktspace.com/]Mikktspace[/url] if the input meshes don't have tangent data. When possible, it's recommended to let the 3D modeling software generate tangents on export instead of relying on this option. Tangents are required for correct display of normal and height maps, along with any material/shader features that require tangents.
|
|
If you don't need material features that require tangents, disabling this can reduce output file size and speed up importing if the source 3D file doesn't contain tangents.
|
|
</constant>
|
|
<constant name="IMPORT_FLAG_USE_NAMED_SKIN_BINDS" value="16" enum="ImportFlags" is_bitfield="true">
|
|
If checked, use named [Skin]s for animation. The [MeshInstance3D] node contains 3 properties of relevance here: a skeleton [NodePath] pointing to the [Skeleton3D] node (usually [code]..[/code]), a mesh, and a skin:
|
|
- The [Skeleton3D] node contains a list of bones with names, their pose and rest, a name, and a parent bone.
|
|
- The mesh is all of the raw vertex data needed to display a mesh. In terms of the mesh, it knows how vertices are weight-painted and uses some internal numbering often imported from 3D modeling software.
|
|
- The skin contains the information necessary to bind this mesh onto this Skeleton3D. For each of the internal bone IDs chosen by the 3D modeling software, it contains two things. Firstly, a matrix known as the Bind Pose Matrix, Inverse Bind Matrix, or IBM for short. Secondly, the [Skin] contains each bone's name (if this flag is enabled), or the bone's index within the [Skeleton3D] list (if this flag is disabled).
|
|
Together, this information is enough to tell Godot how to use the bone poses in the [Skeleton3D] node to render the mesh from each [MeshInstance3D]. Note that each [MeshInstance3D] may share binds, as is common in models exported from Blender, or each [MeshInstance3D] may use a separate [Skin] object, as is common in models exported from other tools such as Maya.
|
|
</constant>
|
|
<constant name="IMPORT_FLAG_DISCARD_MESHES_AND_MATERIALS" value="32" enum="ImportFlags" is_bitfield="true">
|
|
Ignore meshes and materials on import. When importing a scene as an [AnimationLibrary], this flag is always enabled.
|
|
</constant>
|
|
<constant name="IMPORT_FLAG_FORCE_DISABLE_MESH_COMPRESSION" value="64" enum="ImportFlags" is_bitfield="true">
|
|
If [code]true[/code], mesh compression will not be used. Consider enabling if you notice blocky artifacts in your mesh normals or UVs, or if you have meshes that are larger than a few thousand meters in each direction.
|
|
</constant>
|
|
</constants>
|
|
</class>
|