Up to date

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

GLTFState

Inherits: Resource < RefCounted < Object

Represents all data of a GLTF file.

Description

Contains all nodes and resources of a GLTF file. This is used by GLTFDocument as data storage, which allows GLTFDocument and all GLTFDocumentExtension classes to remain stateless.

GLTFState can be populated by GLTFDocument reading a file or by converting a Godot scene. Then the data can either be used to create a Godot scene or save to a GLTF file. The code that converts to/from a Godot scene can be intercepted at arbitrary points by GLTFDocumentExtension classes. This allows for custom data to be stored in the GLTF file or for custom data to be converted to/from Godot nodes.

Properties

String

base_path

“”

PackedByteArray[]

buffers

[]

bool

create_animations

true

PackedByteArray

glb_data

PackedByteArray()

Dictionary

json

{}

int

major_version

0

int

minor_version

0

PackedInt32Array

root_nodes

PackedInt32Array()

String

scene_name

“”

bool

use_named_skin_binds

false

Methods

void

add_used_extension ( String extension_name, bool required )

GLTFAccessor[]

get_accessors ( )

Variant

get_additional_data ( StringName extension_name )

AnimationPlayer

get_animation_player ( int idx )

int

get_animation_players_count ( int idx )

GLTFAnimation[]

get_animations ( )

GLTFBufferView[]

get_buffer_views ( )

GLTFCamera[]

get_cameras ( )

int

get_handle_binary_image ( )

Texture2D[]

get_images ( )

GLTFLight[]

get_lights ( )

Material[]

get_materials ( )

GLTFMesh[]

get_meshes ( )

GLTFNode[]

get_nodes ( )

Node

get_scene_node ( int idx )

GLTFSkeleton[]

get_skeletons ( )

GLTFSkin[]

get_skins ( )

GLTFTextureSampler[]

get_texture_samplers ( )

GLTFTexture[]

get_textures ( )

String[]

get_unique_animation_names ( )

String[]

get_unique_names ( )

void

set_accessors ( GLTFAccessor[] accessors )

void

set_additional_data ( StringName extension_name, Variant additional_data )

void

set_animations ( GLTFAnimation[] animations )

void

set_buffer_views ( GLTFBufferView[] buffer_views )

void

set_cameras ( GLTFCamera[] cameras )

void

set_handle_binary_image ( int method )

void

set_images ( Texture2D[] images )

void

set_lights ( GLTFLight[] lights )

void

set_materials ( Material[] materials )

void

set_meshes ( GLTFMesh[] meshes )

void

set_nodes ( GLTFNode[] nodes )

void

set_skeletons ( GLTFSkeleton[] skeletons )

void

set_skins ( GLTFSkin[] skins )

void

set_texture_samplers ( GLTFTextureSampler[] texture_samplers )

void

set_textures ( GLTFTexture[] textures )

void

set_unique_animation_names ( String[] unique_animation_names )

void

set_unique_names ( String[] unique_names )


Constants

HANDLE_BINARY_DISCARD_TEXTURES = 0

Discards all embedded textures and uses untextured materials.

HANDLE_BINARY_EXTRACT_TEXTURES = 1

Extracts embedded textures to be reimported and compressed. Editor only. Acts as uncompressed at runtime.

HANDLE_BINARY_EMBED_AS_BASISU = 2

Embeds textures VRAM compressed with Basis Universal into the generated scene.

HANDLE_BINARY_EMBED_AS_UNCOMPRESSED = 3

Embeds textures compressed losslessly into the generated scene, matching old behavior.


Property Descriptions

String base_path = ""

  • void set_base_path ( String value )

  • String get_base_path ( )

There is currently no description for this property. Please help us by contributing one!


PackedByteArray[] buffers = []

There is currently no description for this property. Please help us by contributing one!


bool create_animations = true

  • void set_create_animations ( bool value )

  • bool get_create_animations ( )

There is currently no description for this property. Please help us by contributing one!


PackedByteArray glb_data = PackedByteArray()

There is currently no description for this property. Please help us by contributing one!


Dictionary json = {}

There is currently no description for this property. Please help us by contributing one!


int major_version = 0

  • void set_major_version ( int value )

  • int get_major_version ( )

There is currently no description for this property. Please help us by contributing one!


int minor_version = 0

  • void set_minor_version ( int value )

  • int get_minor_version ( )

There is currently no description for this property. Please help us by contributing one!


PackedInt32Array root_nodes = PackedInt32Array()

The root nodes of the GLTF file. Typically, a GLTF file will only have one scene, and therefore one root node. However, a GLTF file may have multiple scenes and therefore multiple root nodes, which will be generated as siblings of each other and as children of the root node of the generated Godot scene.


String scene_name = ""

  • void set_scene_name ( String value )

  • String get_scene_name ( )

The name of the scene. When importing, if not specified, this will be the file name. When exporting, if specified, the scene name will be saved to the GLTF file.


bool use_named_skin_binds = false

  • void set_use_named_skin_binds ( bool value )

  • bool get_use_named_skin_binds ( )

There is currently no description for this property. Please help us by contributing one!


Method Descriptions

void add_used_extension ( String extension_name, bool required )

Appends an extension to the list of extensions used by this GLTF file during serialization. If required is true, the extension will also be added to the list of required extensions. Do not run this in GLTFDocumentExtension._export_post, as that stage is too late to add extensions. The final list is sorted alphabetically.


GLTFAccessor[] get_accessors ( )

There is currently no description for this method. Please help us by contributing one!


Variant get_additional_data ( StringName extension_name )

Gets additional arbitrary data in this GLTFState instance. This can be used to keep per-file state data in GLTFDocumentExtension classes, which is important because they are stateless.

The argument should be the GLTFDocumentExtension name (does not have to match the extension name in the GLTF file), and the return value can be anything you set. If nothing was set, the return value is null.


AnimationPlayer get_animation_player ( int idx )

Returns the AnimationPlayer node with the given index. These nodes are only used during the export process when converting Godot AnimationPlayer nodes to GLTF animations.


int get_animation_players_count ( int idx )

Returns the number of AnimationPlayer nodes in this GLTFState. These nodes are only used during the export process when converting Godot AnimationPlayer nodes to GLTF animations.


GLTFAnimation[] get_animations ( )

Returns an array of all GLTFAnimations in the GLTF file. When importing, these will be generated as animations in an AnimationPlayer node. When exporting, these will be generated from Godot AnimationPlayer nodes.


GLTFBufferView[] get_buffer_views ( )

There is currently no description for this method. Please help us by contributing one!


GLTFCamera[] get_cameras ( )

Returns an array of all GLTFCameras in the GLTF file. These are the cameras that the GLTFNode.camera index refers to.


int get_handle_binary_image ( )

There is currently no description for this method. Please help us by contributing one!


Texture2D[] get_images ( )

There is currently no description for this method. Please help us by contributing one!


GLTFLight[] get_lights ( )

Returns an array of all GLTFLights in the GLTF file. These are the lights that the GLTFNode.light index refers to.


Material[] get_materials ( )

There is currently no description for this method. Please help us by contributing one!


GLTFMesh[] get_meshes ( )

Returns an array of all GLTFMeshes in the GLTF file. These are the meshes that the GLTFNode.mesh index refers to.


GLTFNode[] get_nodes ( )

Returns an array of all GLTFNodes in the GLTF file. These are the nodes that GLTFNode.children and root_nodes refer to. This includes nodes that may not be generated in the Godot scene, or nodes that may generate multiple Godot scene nodes.


Node get_scene_node ( int idx )

Returns the Godot scene node that corresponds to the same index as the GLTFNode it was generated from. Not every GLTFNode will have a scene node generated, and not every generated scene node will have a corresponding GLTFNode.


GLTFSkeleton[] get_skeletons ( )

Returns an array of all GLTFSkeletons in the GLTF file. These are the skeletons that the GLTFNode.skeleton index refers to.


GLTFSkin[] get_skins ( )

Returns an array of all GLTFSkins in the GLTF file. These are the skins that the GLTFNode.skin index refers to.


GLTFTextureSampler[] get_texture_samplers ( )

Retrieves the array of texture samplers that are used by the textures contained in the GLTF.


GLTFTexture[] get_textures ( )

There is currently no description for this method. Please help us by contributing one!


String[] get_unique_animation_names ( )

Returns an array of unique animation names. This is only used during the import process.


String[] get_unique_names ( )

Returns an array of unique node names. This is used in both the import process and export process.


void set_accessors ( GLTFAccessor[] accessors )

There is currently no description for this method. Please help us by contributing one!


void set_additional_data ( StringName extension_name, Variant additional_data )

Sets additional arbitrary data in this GLTFState instance. This can be used to keep per-file state data in GLTFDocumentExtension classes, which is important because they are stateless.

The first argument should be the GLTFDocumentExtension name (does not have to match the extension name in the GLTF file), and the second argument can be anything you want.


void set_animations ( GLTFAnimation[] animations )

Sets the GLTFAnimations in the state. When importing, these will be generated as animations in an AnimationPlayer node. When exporting, these will be generated from Godot AnimationPlayer nodes.


void set_buffer_views ( GLTFBufferView[] buffer_views )

There is currently no description for this method. Please help us by contributing one!


void set_cameras ( GLTFCamera[] cameras )

Sets the GLTFCameras in the state. These are the cameras that the GLTFNode.camera index refers to.


void set_handle_binary_image ( int method )

There is currently no description for this method. Please help us by contributing one!


void set_images ( Texture2D[] images )

There is currently no description for this method. Please help us by contributing one!


void set_lights ( GLTFLight[] lights )

Sets the GLTFLights in the state. These are the lights that the GLTFNode.light index refers to.


void set_materials ( Material[] materials )

There is currently no description for this method. Please help us by contributing one!


void set_meshes ( GLTFMesh[] meshes )

Sets the GLTFMeshes in the state. These are the meshes that the GLTFNode.mesh index refers to.


void set_nodes ( GLTFNode[] nodes )

Sets the GLTFNodes in the state. These are the nodes that GLTFNode.children and root_nodes refer to. Some of the nodes set here may not be generated in the Godot scene, or may generate multiple Godot scene nodes.


void set_skeletons ( GLTFSkeleton[] skeletons )

Sets the GLTFSkeletons in the state. These are the skeletons that the GLTFNode.skeleton index refers to.


void set_skins ( GLTFSkin[] skins )

Sets the GLTFSkins in the state. These are the skins that the GLTFNode.skin index refers to.


void set_texture_samplers ( GLTFTextureSampler[] texture_samplers )

Sets the array of texture samplers that are used by the textures contained in the GLTF.


void set_textures ( GLTFTexture[] textures )

There is currently no description for this method. Please help us by contributing one!


void set_unique_animation_names ( String[] unique_animation_names )

Sets the unique animation names in the state. This is only used during the import process.


void set_unique_names ( String[] unique_names )

Sets the unique node names in the state. This is used in both the import process and export process.