Table of Contents

Class GltfDocument

Namespace
Godot
Assembly
GodotSharp.dll

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 RegisterGltfDocumentExtension(GltfDocumentExtension, bool). This allows for custom data to be imported and exported.

[GodotClassName("GLTFDocument")]
public class GltfDocument : Resource, IDisposable
Inheritance
GltfDocument
Implements
Inherited Members

Constructors

GltfDocument()

public GltfDocument()

Properties

ImageFormat

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.

public string ImageFormat { get; set; }

Property Value

string

LossyQuality

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

public float LossyQuality { get; set; }

Property Value

float

RootNodeMode

How to process the root node during export. See GltfDocument.RootNodeModeEnum for details. The default and recommended value is SingleRoot.

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.

public GltfDocument.RootNodeModeEnum RootNodeMode { get; set; }

Property Value

GltfDocument.RootNodeModeEnum

Methods

AppendFromBuffer(byte[], string, GltfState, uint)

Takes a byte[] defining a GLTF and imports the data to the given GltfState object through the state parameter.

Note: The basePath tells AppendFromBuffer(byte[], string, GltfState, uint) where to find dependencies and can be empty.

public Error AppendFromBuffer(byte[] bytes, string basePath, GltfState state, uint flags = 0)

Parameters

bytes byte[]
basePath string
state GltfState
flags uint

Returns

Error

AppendFromFile(string, GltfState, uint, string)

Takes a path to a GLTF file and imports the data at that file path to the given GltfState object through the state parameter.

Note: The basePath tells AppendFromFile(string, GltfState, uint, string) where to find dependencies and can be empty.

public Error AppendFromFile(string path, GltfState state, uint flags = 0, string basePath = "")

Parameters

path string
state GltfState
flags uint
basePath string

Returns

Error

AppendFromScene(Node, GltfState, uint)

Takes a Godot Engine scene node and exports it and its descendants to the given GltfState object through the state parameter.

public Error AppendFromScene(Node node, GltfState state, uint flags = 0)

Parameters

node Node
state GltfState
flags uint

Returns

Error

GenerateBuffer(GltfState)

Takes a GltfState object through the state parameter and returns a GLTF byte[].

public byte[] GenerateBuffer(GltfState state)

Parameters

state GltfState

Returns

byte[]

GenerateScene(GltfState, float, bool, bool)

Takes a GltfState object through the state parameter and returns a Godot Engine scene node.

public Node GenerateScene(GltfState state, float bakeFps = 30, bool trimming = false, bool removeImmutableTracks = true)

Parameters

state GltfState
bakeFps float
trimming bool
removeImmutableTracks bool

Returns

Node

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

RegisterGltfDocumentExtension(GltfDocumentExtension, bool)

Registers the given GltfDocumentExtension instance with GLTFDocument. If firstPriority is true, this extension will be run first. Otherwise, it will be run last.

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 GltfState or GltfNode.

public static void RegisterGltfDocumentExtension(GltfDocumentExtension extension, bool firstPriority = false)

Parameters

extension GltfDocumentExtension
firstPriority bool

UnregisterGltfDocumentExtension(GltfDocumentExtension)

Unregisters the given GltfDocumentExtension instance.

public static void UnregisterGltfDocumentExtension(GltfDocumentExtension extension)

Parameters

extension GltfDocumentExtension

WriteToFilesystem(GltfState, string)

Takes a GltfState object through the state parameter and writes a glTF file to the filesystem.

Note: The extension of the glTF file determines if it is a .glb binary file or a .gltf file.

public Error WriteToFilesystem(GltfState state, string path)

Parameters

state GltfState
path string

Returns

Error