GLTFDocument
Hereda: Resource < RefCounted < Object
Heredado por: FBXDocument
Clase para importar y exportar archivos glTF dentro y fuera de Godot.
Descripción
GLTFDocument admite la lectura de datos de un archivo glTF, un búfer o una escena de Godot. Estos datos pueden escribirse en el sistema de archivos, en el búfer o utilizarse para crear una escena de Godot.
Todos los datos de una escena glTF se almacenan en la clase GLTFState. GLTFDocument procesa objetos de estado, pero no contiene ningún dato de escena en sí mismo. GLTFDocument tiene variables miembro para almacenar los ajustes de configuración de la exportación, como el formato de imagen, pero por lo demás no tiene estado. Se pueden procesar varias escenas con la misma configuración utilizando el mismo objeto GLTFDocument y diferentes objetos GLTFState.
GLTFDocument puede ampliarse con funcionalidad arbitraria extendiendo la clase GLTFDocumentExtension y registrándola con GLTFDocument a través de register_gltf_document_extension(). Esto permite importar y exportar datos personalizados.
Tutoriales
Propiedades
|
||
|
||
|
||
|
||
|
||
|
Métodos
append_from_buffer(bytes: PackedByteArray, base_path: String, state: GLTFState, flags: int = 0) |
|
append_from_file(path: String, state: GLTFState, flags: int = 0, base_path: String = "") |
|
append_from_scene(node: Node, state: GLTFState, flags: int = 0) |
|
export_object_model_property(state: GLTFState, node_path: NodePath, godot_node: Node, gltf_node_index: int) static |
|
generate_buffer(state: GLTFState) |
|
generate_scene(state: GLTFState, bake_fps: float = 30, trimming: bool = false, remove_immutable_tracks: bool = true) |
|
get_supported_gltf_extensions() static |
|
import_object_model_property(state: GLTFState, json_pointer: String) static |
|
void |
register_gltf_document_extension(extension: GLTFDocumentExtension, first_priority: bool = false) static |
void |
unregister_gltf_document_extension(extension: GLTFDocumentExtension) static |
write_to_filesystem(state: GLTFState, path: String) |
Enumeraciones
enum RootNodeMode: 🔗
RootNodeMode ROOT_NODE_MODE_SINGLE_ROOT = 0
Treat the Godot scene's root node as the root node of the glTF file, and mark it as the single root node via the GODOT_single_root glTF extension. This will be parsed the same as ROOT_NODE_MODE_KEEP_ROOT if the implementation does not support GODOT_single_root.
RootNodeMode ROOT_NODE_MODE_KEEP_ROOT = 1
Treat the Godot scene's root node as the root node of the glTF file, but do not mark it as anything special. An extra root node will be generated when importing into Godot. This uses only vanilla glTF features. This is equivalent to the behavior in Godot 4.1 and earlier.
RootNodeMode ROOT_NODE_MODE_MULTI_ROOT = 2
Treat the Godot scene's root node as the name of the glTF scene, and add all of its children as root nodes of the glTF file. This uses only vanilla glTF features. This avoids an extra root node, but only the name of the Godot scene's root node will be preserved, as it will not be saved as a node.
enum VisibilityMode: 🔗
VisibilityMode VISIBILITY_MODE_INCLUDE_REQUIRED = 0
If the scene contains any non-visible nodes, include them, mark them as non-visible with KHR_node_visibility, and require that importers respect their non-visibility. Downside: If the importer does not support KHR_node_visibility, the file cannot be imported.
VisibilityMode VISIBILITY_MODE_INCLUDE_OPTIONAL = 1
If the scene contains any non-visible nodes, include them, mark them as non-visible with KHR_node_visibility, and do not impose any requirements on importers. Downside: If the importer does not support KHR_node_visibility, invisible objects will be visible.
VisibilityMode VISIBILITY_MODE_EXCLUDE = 2
If the scene contains any non-visible nodes, do not include them in the export. This is the same as the behavior in Godot 4.4 and earlier. Downside: Invisible nodes will not exist in the exported file.
Descripciones de Propiedades
String fallback_image_format = "None" 🔗
The user-friendly name of the fallback image format. This is used when exporting the glTF file, including writing to a file and writing to a byte array.
This property may only be one of "None", "PNG", or "JPEG", and is only used when the image_format is not one of "None", "PNG", or "JPEG". If having multiple extension image formats is desired, that can be done using a GLTFDocumentExtension class - this property only covers the use case of providing a base glTF fallback image when using a custom image format.
float fallback_image_quality = 0.25 🔗
The quality of the fallback image, if any. For PNG files, this downscales the image on both dimensions by this factor. For JPEG files, this is the lossy quality of the image. A low value is recommended, since including multiple high quality images in a glTF file defeats the file size gains of using a more efficient image format.
The user-friendly name of the export image format. This is used when exporting the glTF file, including writing to a file and writing to a byte array.
By default, Godot allows the following options: "None", "PNG", "JPEG", "Lossless WebP", and "Lossy WebP". Support for more image formats can be added in GLTFDocumentExtension classes. A single extension class can provide multiple options for the specific format to use, or even an option that uses multiple formats at once.
If image_format is a lossy image format, this determines the lossy quality of the image. On a range of 0.0 to 1.0, where 0.0 is the lowest quality and 1.0 is the highest quality. A lossy quality of 1.0 is not the same as lossless.
RootNodeMode root_node_mode = 0 🔗
void set_root_node_mode(value: RootNodeMode)
RootNodeMode get_root_node_mode()
How to process the root node during export. The default and recommended value is ROOT_NODE_MODE_SINGLE_ROOT.
Note: Regardless of how the glTF file is exported, when importing, the root node type and name can be overridden in the scene import settings tab.
VisibilityMode visibility_mode = 0 🔗
void set_visibility_mode(value: VisibilityMode)
VisibilityMode get_visibility_mode()
How to deal with node visibility during export. This setting does nothing if all nodes are visible. The default and recommended value is VISIBILITY_MODE_INCLUDE_REQUIRED, which uses the KHR_node_visibility extension.
Descripciones de Métodos
Error append_from_buffer(bytes: PackedByteArray, base_path: String, state: GLTFState, flags: int = 0) 🔗
Toma un PackedByteArray que define un glTF e importa los datos al objeto GLTFState dado a través del parámetro state.
Nota: El base_path le dice a append_from_buffer() dónde encontrar las dependencias y puede estar vacío.
Error append_from_file(path: String, state: GLTFState, flags: int = 0, base_path: String = "") 🔗
Toma una ruta a un archivo glTF e importa los datos en esa ruta de archivo al objeto GLTFState dado a través del parámetro state.
Nota: El base_path le dice a append_from_file() dónde encontrar las dependencias y puede estar vacío.
Error append_from_scene(node: Node, state: GLTFState, flags: int = 0) 🔗
Toma un nodo de escena de Godot Engine y lo exporta a él y a sus descendientes al objeto GLTFState dado a través del parámetro state.
GLTFObjectModelProperty export_object_model_property(state: GLTFState, node_path: NodePath, godot_node: Node, gltf_node_index: int) static 🔗
Determina una asignación entre el node_path de Godot dado y los punteros JSON del Modelo de Objeto glTF correspondientes en el archivo glTF generado. Los detalles de esta asignación se devuelven en un objeto GLTFObjectModelProperty. Se pueden proporcionar asignaciones adicionales a través del método de devolución de llamada GLTFDocumentExtension._import_object_model_property().
PackedByteArray generate_buffer(state: GLTFState) 🔗
Toma un objeto GLTFState a través del parámetro state y devuelve un PackedByteArray glTF.
Node generate_scene(state: GLTFState, bake_fps: float = 30, trimming: bool = false, remove_immutable_tracks: bool = true) 🔗
Toma un objeto GLTFState a través del parámetro state y devuelve un nodo de escena de Godot Engine.
El parámetro bake_fps anula el bake_fps en state.
PackedStringArray get_supported_gltf_extensions() static 🔗
Devuelve una lista de todas las extensiones glTF compatibles, incluyendo las extensiones compatibles directamente con el motor, y las extensiones compatibles con plugins de usuario que registran clases GLTFDocumentExtension.
Nota: Si este método se ejecuta antes de que se registre un GLTFDocumentExtension, sus extensiones no se incluirán en la lista. Asegúrate de ejecutar este método sólo después de que todas las extensiones estén registradas. Si ejecutas esto cuando arranca el motor, considera esperar un frame antes de llamar a este método para asegurar que todas las extensiones estén registradas.
GLTFObjectModelProperty import_object_model_property(state: GLTFState, json_pointer: String) static 🔗
Determina una asignación entre el Modelo de Objetos glTF dado json_pointer y la(s) ruta(s) de nodo de Godot correspondientes en la escena Godot generada. Los detalles de esta asignación se devuelven en un objeto GLTFObjectModelProperty. Se pueden proporcionar asignaciones adicionales a través del método de retorno GLTFDocumentExtension._export_object_model_property().
void register_gltf_document_extension(extension: GLTFDocumentExtension, first_priority: bool = false) static 🔗
Registra la instancia GLTFDocumentExtension dada con GLTFDocument. Si first_priority es true, esta extensión se ejecutará primero. De lo contrario, se ejecutará al final.
Nota: Al igual que el propio GLTFDocument, todas las clases GLTFDocumentExtension deben ser sin estado para que funcionen correctamente. Si necesitas almacenar datos, utiliza los métodos set_additional_data y get_additional_data en GLTFState o GLTFNode.
void unregister_gltf_document_extension(extension: GLTFDocumentExtension) static 🔗
Anula el registro de la instancia GLTFDocumentExtension dada.
Error write_to_filesystem(state: GLTFState, path: String) 🔗
Toma un objeto GLTFState a través del parámetro state y escribe un archivo glTF en el sistema de archivos.
Nota: La extensión del archivo glTF determina si es un archivo binario .glb o un archivo de texto .gltf.