Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

GLTFState

繼承: Resource < RefCounted < Object

被繼承: FBXState

Represents all data of a glTF file.

說明

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.

教學

屬性

float

bake_fps

30.0

String

base_path

""

Array[PackedByteArray]

buffers

[]

String

copyright

""

bool

create_animations

true

String

filename

""

PackedByteArray

glb_data

PackedByteArray()

HandleBinaryImageMode

handle_binary_image_mode

1

bool

import_as_skeleton_bones

false

Dictionary

json

{}

int

major_version

0

int

minor_version

0

PackedInt32Array

root_nodes

PackedInt32Array()

String

scene_name

""

bool

use_named_skin_binds

false

方法

void

add_used_extension(extension_name: String, required: bool)

int

append_data_to_buffers(data: PackedByteArray, deduplication: bool)

int

append_gltf_node(gltf_node: GLTFNode, godot_scene_node: Node, parent_node_index: int)

Array[GLTFAccessor]

get_accessors() const

Variant

get_additional_data(extension_name: StringName) const

AnimationPlayer

get_animation_player(anim_player_index: int) const

int

get_animation_players_count(anim_player_index: int) const

Array[GLTFAnimation]

get_animations() const

Array[GLTFBufferView]

get_buffer_views() const

Array[GLTFCamera]

get_cameras() const

int

get_handle_binary_image() const

Array[Texture2D]

get_images() const

Array[GLTFLight]

get_lights() const

Array[Material]

get_materials() const

Array[GLTFMesh]

get_meshes() const

int

get_node_index(scene_node: Node) const

Array[GLTFNode]

get_nodes() const

Node

get_scene_node(gltf_node_index: int) const

Array[GLTFSkeleton]

get_skeletons() const

Array[GLTFSkin]

get_skins() const

Array[GLTFTextureSampler]

get_texture_samplers() const

Array[GLTFTexture]

get_textures() const

Array[String]

get_unique_animation_names() const

Array[String]

get_unique_names() const

void

set_accessors(accessors: Array[GLTFAccessor])

void

set_additional_data(extension_name: StringName, additional_data: Variant)

void

set_animations(animations: Array[GLTFAnimation])

void

set_buffer_views(buffer_views: Array[GLTFBufferView])

void

set_cameras(cameras: Array[GLTFCamera])

void

set_handle_binary_image(method: int)

void

set_images(images: Array[Texture2D])

void

set_lights(lights: Array[GLTFLight])

void

set_materials(materials: Array[Material])

void

set_meshes(meshes: Array[GLTFMesh])

void

set_nodes(nodes: Array[GLTFNode])

void

set_skeletons(skeletons: Array[GLTFSkeleton])

void

set_skins(skins: Array[GLTFSkin])

void

set_texture_samplers(texture_samplers: Array[GLTFTextureSampler])

void

set_textures(textures: Array[GLTFTexture])

void

set_unique_animation_names(unique_animation_names: Array[String])

void

set_unique_names(unique_names: Array[String])


列舉

enum HandleBinaryImageMode: 🔗

HandleBinaryImageMode HANDLE_BINARY_IMAGE_MODE_DISCARD_TEXTURES = 0

When importing a glTF file with embedded binary images, discards all images and uses untextured materials in their place. Images stored as separate files in the res:// folder are not affected by this; those will be used as Godot imported them.

HandleBinaryImageMode HANDLE_BINARY_IMAGE_MODE_EXTRACT_TEXTURES = 1

When importing a glTF file with embedded binary images, extracts them and saves them to their own files. This allows the image to be imported by Godot's image importer, which can then have their import options customized by the user, including optionally compressing the image to VRAM texture formats.

This will save the images's bytes exactly as-is, without recompression. For image formats supplied by glTF extensions, the file will have a filename ending with the file extension supplied by GLTFDocumentExtension._get_image_file_extension() of the extension class.

Note: This option is editor-only. At runtime, this acts the same as HANDLE_BINARY_IMAGE_MODE_EMBED_AS_UNCOMPRESSED.

HandleBinaryImageMode HANDLE_BINARY_IMAGE_MODE_EMBED_AS_BASISU = 2

When importing a glTF file with embedded binary images, embeds textures VRAM compressed with Basis Universal into the generated scene. Images stored as separate files in the res:// folder are not affected by this; those will be used as Godot imported them.

HandleBinaryImageMode HANDLE_BINARY_IMAGE_MODE_EMBED_AS_UNCOMPRESSED = 3

When importing a glTF file with embedded binary images, embeds textures compressed losslessly into the generated scene. Images stored as separate files in the res:// folder are not affected by this; those will be used as Godot imported them.


常數

HANDLE_BINARY_DISCARD_TEXTURES = 0 🔗

已棄用: Use HANDLE_BINARY_IMAGE_MODE_DISCARD_TEXTURES instead.

丟棄所有內嵌的紋理,並使用無紋理的材質。

HANDLE_BINARY_EXTRACT_TEXTURES = 1 🔗

已棄用: Use HANDLE_BINARY_IMAGE_MODE_EXTRACT_TEXTURES instead.

提取內嵌的紋理以重新匯入和壓縮。僅限編輯器。在運作時充當未壓縮的。

HANDLE_BINARY_EMBED_AS_BASISU = 2 🔗

已棄用: Use HANDLE_BINARY_IMAGE_MODE_EMBED_AS_BASISU instead.

將使用 Basis Universal 壓縮的紋理 VRAM 嵌入到生成的場景中。

HANDLE_BINARY_EMBED_AS_UNCOMPRESSED = 3 🔗

已棄用: Use HANDLE_BINARY_IMAGE_MODE_EMBED_AS_UNCOMPRESSED instead.

將無失真壓縮的紋理嵌入到生成的場景中,配對舊行為。


屬性說明

float bake_fps = 30.0 🔗

  • void set_bake_fps(value: float)

  • float get_bake_fps()

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


String base_path = "" 🔗

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.


Array[PackedByteArray] buffers = [] 🔗

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


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.


bool create_animations = true 🔗

  • void set_create_animations(value: bool)

  • bool get_create_animations()

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


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


PackedByteArray glb_data = PackedByteArray() 🔗

The binary buffer attached to a .glb file.

Note: The returned array is copied and any changes to it will not update the original property value. See PackedByteArray for more details.


HandleBinaryImageMode handle_binary_image_mode = 1 🔗

When importing a glTF file with unimported raw binary images embedded inside of binary blob buffers, in data URIs, or separate files not imported by Godot, this controls how the images are handled. Images can be discarded, saved as separate files, or embedded in the scene lossily or losslessly. See HandleBinaryImageMode for options.

This property does nothing for image files in the res:// folder imported by Godot, as those are handled by Godot's image importer directly, and then the Godot scene generated from the glTF file will use the images as Godot imported them.


bool import_as_skeleton_bones = false 🔗

  • void set_import_as_skeleton_bones(value: bool)

  • bool get_import_as_skeleton_bones()

If true, forces all GLTFNodes in the document to be bones of a single Skeleton3D Godot node.


Dictionary json = {} 🔗

The original raw JSON document corresponding to this GLTFState.


int major_version = 0 🔗

  • void set_major_version(value: int)

  • 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(value: int)

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

Note: The returned array is copied and any changes to it will not update the original property value. See PackedInt32Array for more details.


String scene_name = "" 🔗

  • void set_scene_name(value: String)

  • 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(value: bool)

  • bool get_use_named_skin_binds()

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


方法說明

void add_used_extension(extension_name: String, required: 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 GLTFDocumentExtension._export_post(), as that stage is too late to add extensions. The final list is sorted alphabetically.


int append_data_to_buffers(data: PackedByteArray, deduplication: 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 are first searched for duplicate data, otherwise new bytes are always appended.


int append_gltf_node(gltf_node: GLTFNode, godot_scene_node: Node, parent_node_index: int) 🔗

Appends the given GLTFNode to the state, and returns its new index. This can be used to export one Godot node as multiple glTF nodes, or inject new glTF nodes at import time. On import, this must be called before GLTFDocumentExtension._generate_scene_node() finishes for the parent node. On export, this must be called before GLTFDocumentExtension._export_node() runs for the parent node.

The godot_scene_node parameter is the Godot scene node that corresponds to this glTF node. This is highly recommended to be set to a valid node, but may be null if there is no corresponding Godot scene node. One Godot scene node may be used for multiple glTF nodes, so if exporting multiple glTF nodes for one Godot scene node, use the same Godot scene node for each.

The parent_node_index parameter is the index of the parent GLTFNode in the state. If -1, the node will be a root node, otherwise the new node will be added to the parent's list of children. The index will also be written to the GLTFNode.parent property of the new node.


Array[GLTFAccessor] get_accessors() const 🔗

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


Variant get_additional_data(extension_name: StringName) const 🔗

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(anim_player_index: int) const 🔗

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(anim_player_index: int) const 🔗

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.


Array[GLTFAnimation] get_animations() const 🔗

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.


Array[GLTFBufferView] get_buffer_views() const 🔗

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


Array[GLTFCamera] get_cameras() const 🔗

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() const 🔗

已棄用: Use handle_binary_image_mode instead.

Deprecated untyped alias for handle_binary_image_mode. When importing a glTF file with unimported raw binary images embedded inside of binary blob buffers, in data URIs, or separate files not imported by Godot, this controls how the images are handled.


Array[Texture2D] get_images() const 🔗

Gets the images of the glTF file as an array of Texture2Ds. These are the images that the GLTFTexture.src_image index refers to.


Array[GLTFLight] get_lights() const 🔗

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


Array[Material] get_materials() const 🔗

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


Array[GLTFMesh] get_meshes() const 🔗

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


int get_node_index(scene_node: Node) const 🔗

返回與該 Godot 場景節點對應的 GLTFNode 的索引。這個方法與 get_scene_node() 互逆。可以在匯出過程中使用。

注意:並不是所有 Godot 場景節點都有對應的 GLTFNode,也並不是所有 GLTFNode 都會生成場景節點。如果該場景節點沒有 GLTFNode 索引,則會返回 -1


Array[GLTFNode] get_nodes() const 🔗

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(gltf_node_index: int) const 🔗

返回指定索引的 GLTFNode 對應生成的 Godot 場景節點。這個方法與 get_node_index() 互逆。可以在匯入過程中使用。

注意:並不是所有 GLTFNode 都會生成場景節點,也並不是所有 Godot 場景節點都有對應的 GLTFNode。如果該 GLTFNode 索引沒有場景節點,則會返回 null


Array[GLTFSkeleton] get_skeletons() const 🔗

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


Array[GLTFSkin] get_skins() const 🔗

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


Array[GLTFTextureSampler] get_texture_samplers() const 🔗

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


Array[GLTFTexture] get_textures() const 🔗

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


Array[String] get_unique_animation_names() const 🔗

返回一組唯一的動畫名稱。這僅在匯入過程中使用。


Array[String] get_unique_names() const 🔗

返回唯一節點名稱的陣列。這用於匯入過程和匯出過程。


void set_accessors(accessors: Array[GLTFAccessor]) 🔗

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


void set_additional_data(extension_name: StringName, additional_data: 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.


void set_animations(animations: Array[GLTFAnimation]) 🔗

設定該狀態中的 GLTFAnimation。匯入時,這些將在 AnimationPlayer 節點中生成為動畫。匯出時,這些將由 Godot AnimationPlayer 節點生成。


void set_buffer_views(buffer_views: Array[GLTFBufferView]) 🔗

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


void set_cameras(cameras: Array[GLTFCamera]) 🔗

設定該狀態中的 GLTFCamera。這些是 GLTFNode.camera 索引引用的相機。


void set_handle_binary_image(method: int) 🔗

已棄用: Use handle_binary_image_mode instead.

Deprecated untyped alias for handle_binary_image_mode. When importing a glTF file with unimported raw binary images embedded inside of binary blob buffers, in data URIs, or separate files not imported by Godot, this controls how the images are handled.


void set_images(images: Array[Texture2D]) 🔗

設定狀態中以 Texture2D 陣列形式儲存的圖像。可以在匯出時使用。這些是 GLTFTexture.src_image 索引所引用的圖像。


void set_lights(lights: Array[GLTFLight]) 🔗

設定該狀態中的 GLTFLight。這些是 GLTFNode.light 索引引用的燈。


void set_materials(materials: Array[Material]) 🔗

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


void set_meshes(meshes: Array[GLTFMesh]) 🔗

設定該狀態中的 GLTFMesh。這些是 GLTFNode.mesh 索引引用的網格。


void set_nodes(nodes: Array[GLTFNode]) 🔗

設定該狀態中的 GLTFNode。這些是 GLTFNode.childrenroot_nodes 引用的節點。這裡設定的一些節點在 Godot 場景中可能不會生成,也可能會生成多個 Godot 場景節點。


void set_skeletons(skeletons: Array[GLTFSkeleton]) 🔗

設定該狀態中的 GLTFSkeleton。這些是 GLTFNode.skeleton 索引引用的骨架。


void set_skins(skins: Array[GLTFSkin]) 🔗

設定該狀態中的 GLTFSkin。這些是 GLTFNode.skin 索引引用的皮膚。


void set_texture_samplers(texture_samplers: Array[GLTFTextureSampler]) 🔗

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


void set_textures(textures: Array[GLTFTexture]) 🔗

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


void set_unique_animation_names(unique_animation_names: Array[String]) 🔗

設定該狀態中的唯一動畫名稱。這僅在匯入過程中使用。


void set_unique_names(unique_names: Array[String]) 🔗

設定該狀態中的唯一節點名稱。這用於匯入過程和匯出過程。