Up to date

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

GLTFDocumentExtension

Inherits: Resource < RefCounted < Object

Inherited By: GLTFDocumentExtensionConvertImporterMesh

GLTFDocument extension class.

Description

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 GLTFDocument.register_gltf_document_extension.

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.

Tutorials

Methods

void

_convert_scene_node ( GLTFState state, GLTFNode gltf_node, Node scene_node ) virtual

Error

_export_node ( GLTFState state, GLTFNode gltf_node, Dictionary json, Node node ) virtual

Error

_export_post ( GLTFState state ) virtual

Error

_export_preflight ( GLTFState state, Node root ) virtual

Error

_export_preserialize ( GLTFState state ) virtual

Node3D

_generate_scene_node ( GLTFState state, GLTFNode gltf_node, Node scene_parent ) virtual

String

_get_image_file_extension ( ) virtual

PackedStringArray

_get_saveable_image_formats ( ) virtual

PackedStringArray

_get_supported_extensions ( ) virtual

Error

_import_node ( GLTFState state, GLTFNode gltf_node, Dictionary json, Node node ) virtual

Error

_import_post ( GLTFState state, Node root ) virtual

Error

_import_post_parse ( GLTFState state ) virtual

Error

_import_preflight ( GLTFState state, PackedStringArray extensions ) virtual

Error

_parse_image_data ( GLTFState state, PackedByteArray image_data, String mime_type, Image ret_image ) virtual

Error

_parse_node_extensions ( GLTFState state, GLTFNode gltf_node, Dictionary extensions ) virtual

Error

_parse_texture_json ( GLTFState state, Dictionary texture_json, GLTFTexture ret_gltf_texture ) virtual

Error

_save_image_at_path ( GLTFState state, Image image, String file_path, String image_format, float lossy_quality ) virtual

PackedByteArray

_serialize_image_to_bytes ( GLTFState state, Image image, Dictionary image_dict, String image_format, float lossy_quality ) virtual

Error

_serialize_texture_json ( GLTFState state, Dictionary texture_json, GLTFTexture gltf_texture, String image_format ) virtual


Method Descriptions

void _convert_scene_node ( GLTFState state, GLTFNode gltf_node, Node scene_node ) virtual

Part of the export process. This method is run after _export_preflight and before _export_preserialize.

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


Error _export_node ( GLTFState state, GLTFNode gltf_node, Dictionary json, Node node ) virtual

Part of the export process. This method is run after _get_saveable_image_formats and before _export_post. If this GLTFDocumentExtension is used for exporting images, this runs after _serialize_texture_json.

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


Error _export_post ( GLTFState state ) virtual

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.


Error _export_preflight ( GLTFState state, Node root ) virtual

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 @GlobalScope.OK, the export will use this GLTFDocumentExtension instance. If not overridden, @GlobalScope.OK is returned.


Error _export_preserialize ( GLTFState state ) virtual

Part of the export process. This method is run after _convert_scene_node and before _get_saveable_image_formats.

This method can be used to alter the state before performing serialization. It runs every time when generating a buffer with GLTFDocument.generate_buffer or writing to the file system with GLTFDocument.write_to_filesystem.


Node3D _generate_scene_node ( GLTFState state, GLTFNode gltf_node, Node scene_parent ) virtual

Part of the import process. This method is run after _import_post_parse and before _import_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 scene_parent parameter may be null if this is the single root node.