Table of Contents

Class GltfDocumentExtension

Namespace
Godot
Assembly
GodotSharp.dll

Extends the functionality of the GltfDocument class by allowing you to run arbitrary code at various stages of GLTF import or export.

To use, make a new class extending GLTFDocumentExtension, override any methods you need, make an instance of your class, and register it using RegisterGltfDocumentExtension(GltfDocumentExtension, bool).

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.

[GodotClassName("GLTFDocumentExtension")]
public class GltfDocumentExtension : Resource, IDisposable
Inheritance
GltfDocumentExtension
Implements
Derived
Inherited Members

Constructors

GltfDocumentExtension()

public GltfDocumentExtension()

Methods

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

_ConvertSceneNode(GltfState, GltfNode, Node)

Part of the export process. This method is run after _ExportPreflight(GltfState, Node) and before _ExportPreserialize(GltfState).

Runs when converting the data from a Godot scene node. This method can be used to process the Godot scene node data into a format that can be used by _ExportNode(GltfState, GltfNode, Dictionary, Node).

public virtual void _ConvertSceneNode(GltfState state, GltfNode gltfNode, Node sceneNode)

Parameters

state GltfState
gltfNode GltfNode
sceneNode Node

_ExportNode(GltfState, GltfNode, Dictionary, Node)

Part of the export process. This method is run after _GetSaveableImageFormats() and before _ExportPost(GltfState). If this GltfDocumentExtension is used for exporting images, this runs after _SerializeTextureJson(GltfState, Dictionary, GltfTexture, string).

This method can be used to modify the final JSON of each node.

public virtual Error _ExportNode(GltfState state, GltfNode gltfNode, Dictionary json, Node node)

Parameters

state GltfState
gltfNode GltfNode
json Dictionary
node Node

Returns

Error

_ExportPost(GltfState)

Part of the export process. This method is run last, after all other parts of the export process.

This method can be used to modify the final JSON of the generated GLTF file.

public virtual Error _ExportPost(GltfState state)

Parameters

state GltfState

Returns

Error

_ExportPreflight(GltfState, Node)

Part of the export process. This method is run first, before all other parts of the export process.

The return value is used to determine if this GltfDocumentExtension instance should be used for exporting a given GLTF file. If Ok, the export will use this GltfDocumentExtension instance. If not overridden, Ok is returned.

public virtual Error _ExportPreflight(GltfState state, Node root)

Parameters

state GltfState
root Node

Returns

Error

_ExportPreserialize(GltfState)

Part of the export process. This method is run after _ConvertSceneNode(GltfState, GltfNode, Node) and before _GetSaveableImageFormats().

This method can be used to alter the state before performing serialization. It runs every time when generating a buffer with GenerateBuffer(GltfState) or writing to the file system with WriteToFilesystem(GltfState, string).

public virtual Error _ExportPreserialize(GltfState state)

Parameters

state GltfState

Returns

Error

_GenerateSceneNode(GltfState, GltfNode, Node)

Part of the import process. This method is run after _ImportPostParse(GltfState) and before _ImportNode(GltfState, GltfNode, Dictionary, Node).

Runs when generating a Godot scene node from a GLTFNode. The returned node will be added to the scene tree. Multiple nodes can be generated in this step if they are added as a child of the returned node.

Note: The sceneParent parameter may be null if this is the single root node.

public virtual Node3D _GenerateSceneNode(GltfState state, GltfNode gltfNode, Node sceneParent)

Parameters

state GltfState
gltfNode GltfNode
sceneParent Node

Returns

Node3D

_GetImageFileExtension()

Returns the file extension to use for saving image data into, for example, ".png". If defined, when this extension is used to handle images, and the images are saved to a separate file, the image bytes will be copied to a file with this extension. If this is set, there should be a ResourceImporter class able to import the file. If not defined or empty, Godot will save the image into a PNG file.

public virtual string _GetImageFileExtension()

Returns

string

_GetSaveableImageFormats()

Part of the export process. This method is run after _ConvertSceneNode(GltfState, GltfNode, Node) and before _ExportNode(GltfState, GltfNode, Dictionary, Node).

Returns an array of the image formats that can be saved/exported by this extension. This extension will only be selected as the image exporter if the GltfDocument's ImageFormat is in this array. If this GltfDocumentExtension is selected as the image exporter, one of the _SaveImageAtPath(GltfState, Image, string, string, float) or _SerializeImageToBytes(GltfState, Image, Dictionary, string, float) methods will run next, otherwise _ExportNode(GltfState, GltfNode, Dictionary, Node) will run next. If the format name contains "Lossy", the lossy quality slider will be displayed.

public virtual string[] _GetSaveableImageFormats()

Returns

string[]

_GetSupportedExtensions()

Part of the import process. This method is run after _ImportPreflight(GltfState, string[]) and before _ParseNodeExtensions(GltfState, GltfNode, Dictionary).

Returns an array of the GLTF extensions supported by this GLTFDocumentExtension class. This is used to validate if a GLTF file with required extensions can be loaded.

public virtual string[] _GetSupportedExtensions()

Returns

string[]

_ImportNode(GltfState, GltfNode, Dictionary, Node)

Part of the import process. This method is run after _GenerateSceneNode(GltfState, GltfNode, Node) and before _ImportPost(GltfState, Node).

This method can be used to make modifications to each of the generated Godot scene nodes.

public virtual Error _ImportNode(GltfState state, GltfNode gltfNode, Dictionary json, Node node)

Parameters

state GltfState
gltfNode GltfNode
json Dictionary
node Node

Returns

Error

_ImportPost(GltfState, Node)

Part of the import process. This method is run last, after all other parts of the import process.

This method can be used to modify the final Godot scene generated by the import process.

public virtual Error _ImportPost(GltfState state, Node root)

Parameters

state GltfState
root Node

Returns

Error

_ImportPostParse(GltfState)

Part of the import process. This method is run after _ParseNodeExtensions(GltfState, GltfNode, Dictionary) and before _GenerateSceneNode(GltfState, GltfNode, Node).

This method can be used to modify any of the data imported so far, including any scene nodes, before running the final per-node import step.

public virtual Error _ImportPostParse(GltfState state)

Parameters

state GltfState

Returns

Error

_ImportPreflight(GltfState, string[])

Part of the import process. This method is run first, before all other parts of the import process.

The return value is used to determine if this GltfDocumentExtension instance should be used for importing a given GLTF file. If Ok, the import will use this GltfDocumentExtension instance. If not overridden, Ok is returned.

public virtual Error _ImportPreflight(GltfState state, string[] extensions)

Parameters

state GltfState
extensions string[]

Returns

Error

_ParseImageData(GltfState, byte[], string, Image)

Part of the import process. This method is run after _ParseNodeExtensions(GltfState, GltfNode, Dictionary) and before _ParseTextureJson(GltfState, Dictionary, GltfTexture).

Runs when parsing image data from a GLTF file. The data could be sourced from a separate file, a URI, or a buffer, and then is passed as a byte array.

public virtual Error _ParseImageData(GltfState state, byte[] imageData, string mimeType, Image retImage)

Parameters

state GltfState
imageData byte[]
mimeType string
retImage Image

Returns

Error

_ParseNodeExtensions(GltfState, GltfNode, Dictionary)

Part of the import process. This method is run after _GetSupportedExtensions() and before _ImportPostParse(GltfState).

Runs when parsing the node extensions of a GLTFNode. This method can be used to process the extension JSON data into a format that can be used by _GenerateSceneNode(GltfState, GltfNode, Node). The return value should be a member of the Error enum.

public virtual Error _ParseNodeExtensions(GltfState state, GltfNode gltfNode, Dictionary extensions)

Parameters

state GltfState
gltfNode GltfNode
extensions Dictionary

Returns

Error

_ParseTextureJson(GltfState, Dictionary, GltfTexture)

Part of the import process. This method is run after _ParseImageData(GltfState, byte[], string, Image) and before _GenerateSceneNode(GltfState, GltfNode, Node).

Runs when parsing the texture JSON from the GLTF textures array. This can be used to set the source image index to use as the texture.

public virtual Error _ParseTextureJson(GltfState state, Dictionary textureJson, GltfTexture retGltfTexture)

Parameters

state GltfState
textureJson Dictionary
retGltfTexture GltfTexture

Returns

Error

_SaveImageAtPath(GltfState, Image, string, string, float)

Part of the export process. This method is run after _GetSaveableImageFormats() and before _SerializeTextureJson(GltfState, Dictionary, GltfTexture, string).

This method is run when saving images separately from the GLTF file. When images are embedded, _SerializeImageToBytes(GltfState, Image, Dictionary, string, float) runs instead. Note that these methods only run when this GltfDocumentExtension is selected as the image exporter.

public virtual Error _SaveImageAtPath(GltfState state, Image image, string filePath, string imageFormat, float lossyQuality)

Parameters

state GltfState
image Image
filePath string
imageFormat string
lossyQuality float

Returns

Error

_SerializeImageToBytes(GltfState, Image, Dictionary, string, float)

Part of the export process. This method is run after _GetSaveableImageFormats() and before _SerializeTextureJson(GltfState, Dictionary, GltfTexture, string).

This method is run when embedding images in the GLTF file. When images are saved separately, _SaveImageAtPath(GltfState, Image, string, string, float) runs instead. Note that these methods only run when this GltfDocumentExtension is selected as the image exporter.

This method must set the image MIME type in the imageDict with the "mimeType" key. For example, for a PNG image, it would be set to "image/png". The return value must be a byte[] containing the image data.

public virtual byte[] _SerializeImageToBytes(GltfState state, Image image, Dictionary imageDict, string imageFormat, float lossyQuality)

Parameters

state GltfState
image Image
imageDict Dictionary
imageFormat string
lossyQuality float

Returns

byte[]

_SerializeTextureJson(GltfState, Dictionary, GltfTexture, string)

Part of the export process. This method is run after _SaveImageAtPath(GltfState, Image, string, string, float) or _SerializeImageToBytes(GltfState, Image, Dictionary, string, float), and before _ExportNode(GltfState, GltfNode, Dictionary, Node). Note that this method only runs when this GltfDocumentExtension is selected as the image exporter.

This method can be used to set up the extensions for the texture JSON by editing textureJson. The extension must also be added as used extension with AddUsedExtension(string, bool), be sure to set required to true if you are not providing a fallback.

public virtual Error _SerializeTextureJson(GltfState state, Dictionary textureJson, GltfTexture gltfTexture, string imageFormat)

Parameters

state GltfState
textureJson Dictionary
gltfTexture GltfTexture
imageFormat string

Returns

Error