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
HandleBinaryEmbedAsBasisu
Embeds textures VRAM compressed with Basis Universal into the generated scene.
public const long HandleBinaryEmbedAsBasisu = 2
Field Value
HandleBinaryEmbedAsUncompressed
Embeds textures compressed losslessly into the generated scene, matching old behavior.
public const long HandleBinaryEmbedAsUncompressed = 3
Field Value
HandleBinaryExtractTextures
Extracts embedded textures to be reimported and compressed. Editor only. Acts as uncompressed at runtime.
public const long HandleBinaryExtractTextures = 1
Field Value
Properties
BakeFps
The baking fps of the animation for either import or export.
public double BakeFps { get; set; }
Property Value
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
Buffers
public Array<byte[]> Buffers { get; set; }
Property Value
Copyright
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
CreateAnimations
public bool CreateAnimations { get; set; }
Property Value
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
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
Json
The original raw JSON document corresponding to this GLTFState.
public Dictionary Json { get; set; }
Property Value
MajorVersion
public int MajorVersion { get; set; }
Property Value
MinorVersion
public int MinorVersion { get; set; }
Property Value
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
UseNamedSkinBinds
public bool UseNamedSkinBinds { get; set; }
Property Value
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
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
Returns
GetAccessors()
public Array<GltfAccessor> GetAccessors()
Returns
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
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
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
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
GetBufferViews()
public Array<GltfBufferView> GetBufferViews()
Returns
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
GetHandleBinaryImage()
public int GetHandleBinaryImage()
Returns
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
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
GetMaterials()
public Array<Material> GetMaterials()
Returns
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
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
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
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
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
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
GetTextureSamplers()
Retrieves the array of texture samplers that are used by the textures contained in the GLTF.
public Array<GltfTextureSampler> GetTextureSamplers()
Returns
GetTextures()
public Array<GltfTexture> GetTextures()
Returns
GetUniqueAnimationNames()
Returns an array of unique animation names. This is only used during the import process.
public Array<string> GetUniqueAnimationNames()
Returns
GetUniqueNames()
Returns an array of unique node names. This is used in both the import process and export process.
public Array<string> GetUniqueNames()
Returns
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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
StringNameadditionalData
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
SetLights(Array<GltfLight>)
public void SetLights(Array<GltfLight> lights)
Parameters
SetMaterials(Array<Material>)
public void SetMaterials(Array<Material> materials)
Parameters
SetMeshes(Array<GltfMesh>)
public void SetMeshes(Array<GltfMesh> meshes)
Parameters
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
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>)
public void SetSkins(Array<GltfSkin> skins)
Parameters
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
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)