Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

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

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 )


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 ( float value )

  • float get_lossy_quality ( )

If 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.


Method Descriptions

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

接收一个定义 GLTF 的 PackedByteArray,并通过 state 参数将数据导入给定的 GLTFState 对象。

注意:base_pathappend_from_buffer 用作依赖关系的查找路径,可以为空。


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

接收一个 GLTF 文件的路径,并通过 state 参数将该文件路径上的数据导入到给定的 GLTFState 对象。

注意:base_pathappend_from_file 用作依赖关系的查找路径,可以为空。


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

接收一个 Godot 引擎的场景节点,并通过 state 参数将其及其后代导出到给定的 GLTFState 对象。


PackedByteArray generate_buffer ( GLTFState state )

通过 state 参数接收一个 GLTFState 对象,并返回一个 GLTF PackedByteArray


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

通过 state 参数接收一个 GLTFState 对象,并返回一个 Godot 引擎的场景节点。


void register_gltf_document_extension ( GLTFDocumentExtension extension, bool first_priority=false ) static

使用 GLTFDocument 注册给定的 GLTFDocumentExtension 实例。如果 first_priority 为 true,则该扩展将被首先运行。否则,它将被最后运行。

注意:与 GLTFDocument 本身一样,所有 GLTFDocumentExtension 类都必须是无状态的才能正常运行。如果需要存储数据,使用 GLTFStateGLTFNode 中的 set_additional_dataget_additional_data 方法。


void unregister_gltf_document_extension (