Table of Contents

Class GltfState

Namespace
Godot
Assembly
GodotSharp.dll

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.

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

Constructors

GltfState()

public GltfState()

Fields

HandleBinaryDiscardTextures

Discards all embedded textures and uses untextured materials.

public const long HandleBinaryDiscardTextures = 0

Field Value

long

HandleBinaryEmbedAsBasisu

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

public const long HandleBinaryEmbedAsBasisu = 2

Field Value

long

HandleBinaryEmbedAsUncompressed

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

public const long HandleBinaryEmbedAsUncompressed = 3

Field Value

long

HandleBinaryExtractTextures

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

public const long HandleBinaryExtractTextures = 1

Field Value

long

Properties

BakeFps

The baking fps of the animation for either import or export.

public double BakeFps { get; set; }

Property Value

double

BasePath

The folder path associated with this GLTF data. This is used to find other files the GLTF file references, like images or binary buffers. This will be set during import when appending from a file, and will be set during export when writing to a file.

public string BasePath { get; set; }

Property Value

string

Buffers

public Array<byte[]> Buffers { get; set; }

Property Value

Array<byte[]>

The copyright string in the asset header of the GLTF file. This is set during import if present and export if non-empty. See the GLTF asset header documentation for more information.

public string Copyright { get; set; }

Property Value

string

CreateAnimations

public bool CreateAnimations { get; set; }

Property Value

bool

FileName

The file name associated with this GLTF data. If it ends with .gltf, this is text-based GLTF, otherwise this is binary GLB. This will be set during import when appending from a file, and will be set during export when writing to a file. If writing to a buffer, this will be an empty string.

public string FileName { get; set; }

Property Value

string

GlbData

The binary buffer attached to a .glb file.

public byte[] GlbData { get; set; }

Property Value

byte[]

ImportAsSkeletonBones

True to force all GLTFNodes in the document to be bones of a single Skeleton3D godot node.

public bool ImportAsSkeletonBones { get; set; }

Property Value

bool

Json

The original raw JSON document corresponding to this GLTFState.

public Dictionary Json { get; set; }

Property Value

Dictionary

MajorVersion

public int MajorVersion { get; set; }

Property Value

int

MinorVersion

public int MinorVersion { get; set; }

Property Value

int

RootNodes

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.

public int[] RootNodes { get; set; }

Property Value

int[]

SceneName

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.

public string SceneName { get; set; }

Property Value

string

UseNamedSkinBinds

public bool UseNamedSkinBinds { get; set; }

Property Value

bool

Methods

AddUsedExtension(string, bool)

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 _ExportPost(GltfState), as that stage is too late to add extensions. The final list is sorted alphabetically.

public void AddUsedExtension(string extensionName, bool required)

Parameters

extensionName string
required bool

AppendDataToBuffers(byte[], bool)

Appends the given byte array data to the buffers and creates a GltfBufferView for it. The index of the destination GltfBufferView is returned. If deduplication is true, the buffers will first be searched for duplicate data, otherwise new bytes will always be appended.

public int AppendDataToBuffers(byte[] data, bool deduplication)

Parameters

data byte[]
deduplication bool

Returns

int

GetAccessors()

public Array<GltfAccessor> GetAccessors()

Returns

Array<GltfAccessor>

GetAdditionalData(StringName)

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.

public Variant GetAdditionalData(StringName extensionName)

Parameters

extensionName StringName

Returns

Variant

GetAnimationPlayer(int)

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.

public AnimationPlayer GetAnimationPlayer(int idx)

Parameters

idx int

Returns

AnimationPlayer

GetAnimationPlayersCount(int)

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.

public int GetAnimationPlayersCount(int idx)

Parameters

idx int

Returns

int

GetAnimations()

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.

public Array<GltfAnimation> GetAnimations()

Returns

Array<GltfAnimation>

GetBufferViews()

public Array<GltfBufferView> GetBufferViews()

Returns

Array<GltfBufferView>

GetCameras()

Returns an array of all GltfCameras in the GLTF file. These are the cameras that the Camera index refers to.

public Array<GltfCamera> GetCameras()

Returns

Array<GltfCamera>

GetHandleBinaryImage()

public int GetHandleBinaryImage()

Returns

int

GetImages()

Gets the images of the GLTF file as an array of Texture2Ds. These are the images that the SrcImage index refers to.

public Array<Texture2D> GetImages()

Returns

Array<Texture2D>

GetLights()

Returns an array of all GltfLights in the GLTF file. These are the lights that the Light index refers to.

public Array<GltfLight> GetLights()

Returns

Array<GltfLight>

GetMaterials()

public Array<Material> GetMaterials()

Returns

Array<Material>

GetMeshes()

Returns an array of all GltfMeshes in the GLTF file. These are the meshes that the Mesh index refers to.

public Array<GltfMesh> GetMeshes()

Returns

Array<GltfMesh>

GetNodeIndex(Node)

Returns the index of the GltfNode corresponding to this Godot scene node. This is the inverse of GetSceneNode(int). Useful during the export process.

Note: Not every Godot scene node will have a corresponding GltfNode, and not every GltfNode will have a scene node generated. If there is no GltfNode index for this scene node, -1 is returned.

public int GetNodeIndex(Node sceneNode)

Parameters

sceneNode Node

Returns

int

GetNodes()

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

public Array<GltfNode> GetNodes()

Returns

Array<GltfNode>

GetSceneNode(int)

Returns the Godot scene node that corresponds to the same index as the GltfNode it was generated from. This is the inverse of GetNodeIndex(Node). Useful during the import process.

Note: Not every GltfNode will have a scene node generated, and not every generated scene node will have a corresponding GltfNode. If there is no scene node for this GltfNode index, null is returned.

public Node GetSceneNode(int idx)

Parameters

idx int

Returns

Node

GetSkeletons()

Returns an array of all GltfSkeletons in the GLTF file. These are the skeletons that the Skeleton index refers to.

public Array<GltfSkeleton> GetSkeletons()

Returns

Array<GltfSkeleton>

GetSkins()

Returns an array of all GltfSkins in the GLTF file. These are the skins that the Skin index refers to.

public Array<GltfSkin> GetSkins()

Returns

Array<GltfSkin>

GetTextureSamplers()

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

public Array<GltfTextureSampler> GetTextureSamplers()

Returns

Array<GltfTextureSampler>

GetTextures()

public Array<GltfTexture> GetTextures()

Returns

Array<GltfTexture>

GetUniqueAnimationNames()

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

public Array<string> GetUniqueAnimationNames()

Returns

Array<string>

GetUniqueNames()

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

public Array<string> GetUniqueNames()

Returns

Array<string>

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

SetAccessors(Array<GltfAccessor>)

public void SetAccessors(Array<GltfAccessor> accessors)

Parameters

accessors Array<GltfAccessor>

SetAdditionalData(StringName, Variant)

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.

public void SetAdditionalData(StringName extensionName, Variant additionalData)

Parameters

extensionName StringName
additionalData Variant

SetAnimations(Array<GltfAnimation>)

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.

public void SetAnimations(Array<GltfAnimation> animations)

Parameters

animations Array<GltfAnimation>

SetBufferViews(Array<GltfBufferView>)

public void SetBufferViews(Array<GltfBufferView> bufferViews)

Parameters

bufferViews Array<GltfBufferView>

SetCameras(Array<GltfCamera>)

Sets the GltfCameras in the state. These are the cameras that the Camera index refers to.

public void SetCameras(Array<GltfCamera> cameras)

Parameters

cameras Array<GltfCamera>

SetHandleBinaryImage(int)

public void SetHandleBinaryImage(int method)

Parameters

method int

SetImages(Array<Texture2D>)

Sets the images in the state stored as an array of Texture2Ds. This can be used during export. These are the images that the SrcImage index refers to.

public void SetImages(Array<Texture2D> images)

Parameters

images Array<Texture2D>

SetLights(Array<GltfLight>)

Sets the GltfLights in the state. These are the lights that the Light index refers to.

public void SetLights(Array<GltfLight> lights)

Parameters

lights Array<GltfLight>

SetMaterials(Array<Material>)

public void SetMaterials(Array<Material> materials)

Parameters

materials Array<Material>

SetMeshes(Array<GltfMesh>)

Sets the GltfMeshes in the state. These are the meshes that the Mesh index refers to.

public void SetMeshes(Array<GltfMesh> meshes)

Parameters

meshes Array<GltfMesh>

SetNodes(Array<GltfNode>)

Sets the GltfNodes in the state. These are the nodes that Children and RootNodes refer to. Some of the nodes set here may not be generated in the Godot scene, or may generate multiple Godot scene nodes.

public void SetNodes(Array<GltfNode> nodes)

Parameters

nodes Array<GltfNode>

SetSkeletons(Array<GltfSkeleton>)

Sets the GltfSkeletons in the state. These are the skeletons that the Skeleton index refers to.

public void SetSkeletons(Array<GltfSkeleton> skeletons)

Parameters

skeletons Array<GltfSkeleton>

SetSkins(Array<GltfSkin>)

Sets the GltfSkins in the state. These are the skins that the Skin index refers to.

public void SetSkins(Array<GltfSkin> skins)

Parameters

skins Array<GltfSkin>

SetTextureSamplers(Array<GltfTextureSampler>)

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

public void SetTextureSamplers(Array<GltfTextureSampler> textureSamplers)

Parameters

textureSamplers Array<GltfTextureSampler>

SetTextures(Array<GltfTexture>)

public void SetTextures(Array<GltfTexture> textures)

Parameters

textures Array<GltfTexture>

SetUniqueAnimationNames(Array<string>)

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

public void SetUniqueAnimationNames(Array<string> uniqueAnimationNames)

Parameters

uniqueAnimationNames Array<string>

SetUniqueNames(Array<string>)

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

public void SetUniqueNames(Array<string> uniqueNames)

Parameters

uniqueNames Array<string>