GLTFState
继承: Resource < RefCounted < Object
派生: FBXState
代表 glTF 文件中的所有数据。
描述
包含 glTF 文件中的所有节点和资源。用于 GLTFDocument 的数据存储,能够让 GLTFDocument 和所有 GLTFDocumentExtension 类保持无状态。
GLTFState 的填写可以通过 GLTFDocument 读取文件进行,也可以通过转换 Godot 场景进行。填写完成后,可以将数据用于 Godot 场景的创建或者 glTF 文件的保存。与 Godot 场景之间进行转换的代码可以通过 GLTFDocumentExtension 类在任意时刻拦截。这样就能够在 glTF 文件中存储自定义数据,也可以将自定义数据保存到 Godot 节点或者从 Godot 节点读取。
教程
属性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
枚举
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.
将无损压缩的纹理嵌入到生成的场景中,匹配旧行为。
属性说明
用于导入或导出的动画的烘焙 fps。
与该 glTF 数据关联的文件夹路径。这用于查找该 glTF 文件引用的其他文件,例如图像或二进制缓冲区。这将在导入期间从文件追加时设置,并将在导出期间写入文件时设置。
Array[PackedByteArray] buffers = [] 🔗
void set_buffers(value: Array[PackedByteArray])
Array[PackedByteArray] get_buffers()
There is currently no description for this property. Please help us by contributing one!
该 glTF 文件的资产标头中的版权字符串。如果存在,则在导入期间设置;如果非空则在导出期间设置。详见 glTF 资产标头文档。
bool create_animations = true 🔗
There is currently no description for this property. Please help us by contributing one!
与该 glTF 数据关联的文件名。如果它以 .gltf 结尾,则这是基于文本的 glTF,否则这是二进制 GLB。这将在导入期间从文件追加时设置,并将在导出期间写入文件时设置。如果写入到缓冲区,这将是一个空字符串。
PackedByteArray glb_data = PackedByteArray() 🔗
void set_glb_data(value: PackedByteArray)
PackedByteArray get_glb_data()
附加到 .glb 文件的二进制缓冲区。
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 🔗
void set_handle_binary_image_mode(value: HandleBinaryImageMode)
HandleBinaryImageMode get_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. 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 🔗
如果为 true,则强制文档中的所有 GLTFNode 成为单个 Skeleton3D Godot 节点的骨骼。
Dictionary json = {} 🔗
void set_json(value: Dictionary)
Dictionary get_json()
与该 GLTFState 对应的原始 JSON 文档。
There is currently no description for this property. Please help us by contributing one!
There is currently no description for this property. Please help us by contributing one!
PackedInt32Array root_nodes = PackedInt32Array() 🔗
void set_root_nodes(value: PackedInt32Array)
PackedInt32Array get_root_nodes()
glTF 文件的根节点。通常一个 glTF 文件只有一个场景,因此只有一个根节点。然而 glTF 文件可能有多个场景,因此可以有多个根节点,它们将作为彼此的同级节点生成,并作为生成的 Godot 场景的根节点的子节点生成。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedInt32Array for more details.
场景的名称。导入时,如果没有指定,这将是文件名。导出时,如果指定,场景名称将被保存到 glTF 文件中。
bool use_named_skin_binds = false 🔗
There is currently no description for this property. Please help us by contributing one!
方法说明
void add_used_extension(extension_name: String, required: bool) 🔗
在序列化期间,将一个扩展名追加到该 glTF 文件使用的扩展名列表在。如果 required 为 true,则该扩展名也将被添加到所需扩展名列表中。不要在 GLTFDocumentExtension._export_post() 中运行它,因为那个阶段已来不及添加扩展。最终的列表将按字母顺序排序。
int append_data_to_buffers(data: PackedByteArray, deduplication: bool) 🔗
将字节数组数据 data 附加到缓冲区并为其创建一个 GLTFBufferView。返回目标 GLTFBufferView 的索引。如果 deduplication 为 true,则会首先在缓冲区中搜索重复数据,否则会始终追加新字节。
int append_gltf_node(gltf_node: GLTFNode, godot_scene_node: Node, parent_node_index: int) 🔗
将给定的 GLTFNode 追加到状态中并返回其索引。可以用来将一个 Godot 节点导出为多个 glTF 节点,或是在导入时注入新的 glTF 节点。导入时必须在父节点完成 GLTFDocumentExtension._generate_scene_node() 前调用。导出时父节点运行 GLTFDocumentExtension._export_node() 前调用。
参数 godot_scene_node 是与该 glTF 节点对应的 Godot 场景节点。强烈建议将其设为有效节点,但如果没有对应的 Godot 场景节点的话也可以设为 null。一个 Godot 场景节点可以用于多个 glTF 节点,因此为单一 Godot 场景节点导出多个 glTF 节点时,每一个都可以使用相同的 Godot 场景节点。
参数 parent_node_index 是状态中父 GLTFNode 的索引。如果为 -1 则该节点为根节点,否则会将新节点加入父节点的子节点列表。该索引也会写入新节点的 GLTFNode.parent 属性。
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 🔗
在 GLTFState 实例中获取额外的任意数据。这可用于保留在 GLTFDocumentExtension 类中的每个文件的状态数据,这很重要,因为它们是无状态的。
参数应该是 GLTFDocumentExtension 的名称(不必与 glTF 文件中的扩展名相匹配),而返回值可以是你设置的任何东西。如果没有设置任何东西,则返回值为 null。
AnimationPlayer get_animation_player(anim_player_index: int) const 🔗
返回具有给定索引的 AnimationPlayer 节点。这些节点仅在将 Godot AnimationPlayer 节点转换为 glTF 动画时的导出过程中使用。
int get_animation_players_count(anim_player_index: int) const 🔗
返回该 GLTFState 中 AnimationPlayer 节点的数量。这些节点仅在将 Godot AnimationPlayer 节点转换为 glTF 动画时的导出过程中使用。
Array[GLTFAnimation] get_animations() const 🔗
返回 glTF 文件中所有 GLTFAnimation 的数组。导入时,这些将在一个 AnimationPlayer 节点生成为动画。导出时,这些将从 Godot AnimationPlayer 节点生成。
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 🔗
返回 glTF 文件中所有 GLTFCamera 的数组。这些是 GLTFNode.camera 索引引用的相机。
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 🔗
以 Texture2D 数组的形式获取 glTF 文件中的图像。这些是 GLTFTexture.src_image 索引引用的图像。
Array[GLTFLight] get_lights() const 🔗
返回 glTF 文件中所有 GLTFLight 的数组。这些是 GLTFNode.light 索引引用的灯。
Array[Material] get_materials() const 🔗
There is currently no description for this method. Please help us by contributing one!
Array[GLTFMesh] get_meshes() const 🔗
返回 glTF 文件中所有 GLTFMesh 的数组。这些是 GLTFNode.mesh 索引引用的网格。
int get_node_index(scene_node: Node) const 🔗
返回与该 Godot 场景节点对应的 GLTFNode 的索引。这个方法与 get_scene_node() 互逆。可以在导出过程中使用。
注意:并不是所有 Godot 场景节点都有对应的 GLTFNode,也并不是所有 GLTFNode 都会生成场景节点。如果该场景节点没有 GLTFNode 索引,则会返回 -1。
Array[GLTFNode] get_nodes() const 🔗
返回 glTF 文件中所有 GLTFNode 的数组。这些是 GLTFNode.children 和 root_nodes 引用的节点。这包括可能不会在 Godot 场景中生成的节点,或者可能生成多个 Godot 场景节点的节点。
Node get_scene_node(gltf_node_index: int) const 🔗
返回指定索引的 GLTFNode 对应生成的 Godot 场景节点。这个方法与 get_node_index() 互逆。可以在导入过程中使用。
注意:并不是所有 GLTFNode 都会生成场景节点,也并不是所有 Godot 场景节点都有对应的 GLTFNode。如果该 GLTFNode 索引没有场景节点,则会返回 null。
Array[GLTFSkeleton] get_skeletons() const 🔗
返回 glTF 文件中所有 GLTFSkeleton 的数组。这些是 GLTFNode.skeleton 索引引用的骨架。
Array[GLTFSkin] get_skins() const 🔗
返回 glTF 文件中所有 GLTFSkin 的数组。这些是 GLTFNode.skin 索引引用的皮肤。
Array[GLTFTextureSampler] get_texture_samplers() const 🔗
检索 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) 🔗
在这个 GLTFState 实例中设置额外的任意数据。这可以用来保留在 GLTFDocumentExtension 类中的每个文件的状态数据,这很重要,因为它们是无状态的。
第一个参数应该是 GLTFDocumentExtension 的名称(不必与 glTF 文件中的扩展名相匹配),第二个参数可以是任何你想要的东西。
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.children 和 root_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]) 🔗
设置由 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]) 🔗
设置该状态中的唯一节点名称。这用于导入过程和导出过程。