Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

GLTFDocument

Inherits: Resource < RefCounted < Object

Class for importing and exporting glTF files in and out of Godot.

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 register_gltf_document_extension. This allows for custom data to be imported and exported.

Tutorials

Properties

String

image_format

"PNG"

float

lossy_quality

0.75

RootNodeMode

root_node_mode

0

Methods

Error

append_from_buffer ( PackedByteArray bytes, String base_path, GLTFState state, int flags=0 )

Error

append_from_file ( String path, GLTFState state, int flags=0, String base_path="" )

Error

append_from_scene ( Node node, GLTFState state, int flags=0 )

PackedByteArray

generate_buffer ( GLTFState state )

Node

generate_scene ( GLTFState state, float bake_fps=30, bool trimming=false, bool remove_immutable_tracks=true )

void

register_gltf_document_extension ( GLTFDocumentExtension extension, bool first_priority=false ) static

void

unregister_gltf_document_extension ( GLTFDocumentExtension extension ) static

Error

write_to_filesystem ( GLTFState state, String path )


Enumerations

enum RootNodeMode:

RootNodeMode ROOT_NODE_MODE_SINGLE_ROOT = 0

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 ROOT_NODE_MODE_KEEP_ROOT if the implementation does not support GODOT_single_root.

RootNodeMode ROOT_NODE_MODE_KEEP_ROOT = 1

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.

RootNodeMode ROOT_NODE_MODE_MULTI_ROOT = 2

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.


Property Descriptions

String image_format = "PNG"

  • void set_image_format ( String value )

  • String get_image_format ( )

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.


float lossy_quality = 0.75

  • void set_lossy_quality (