Documentation
¶
Overview ¶
Extends the functionality of the graphics.gd/classdb/GLTFDocument class by allowing you to run arbitrary code at various stages of glTF import or export.
To use, make a new class extending GLTFDocumentExtension, override any methods you need, make an instance of your class, and register it using graphics.gd/classdb/GLTFDocument.Instance.RegisterGltfDocumentExtension.
Note: Like GLTFDocument itself, all GLTFDocumentExtension classes must be stateless in order to function properly. If you need to store data, use the set_additional_data and get_additional_data methods in graphics.gd/classdb/GLTFState or graphics.gd/classdb/GLTFNode.
Index ¶
- type Advanced
- type Any
- type Extension
- type ID
- type Implementation
- type Instance
- func (self Instance) AsGLTFDocumentExtension() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) ID() ID
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.
func (*Extension[T]) AsGLTFDocumentExtension ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
type Instance [1]gdclass.GLTFDocumentExtension
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsGLTFDocumentExtension ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
type Interface ¶
type Interface interface { // Part of the import process. This method is run first, before all other parts of the import process. // // The return value is used to determine if this [graphics.gd/classdb/GLTFDocumentExtension] instance should be used for importing a given glTF file. If [Ok], the import will use this [graphics.gd/classdb/GLTFDocumentExtension] instance. If not overridden, [Ok] is returned. ImportPreflight(state GLTFState.Instance, extensions []string) error // Part of the import process. This method is run after [Interface.ImportPreflight] and before [Interface.ParseNodeExtensions]. // // Returns an array of the glTF extensions supported by this GLTFDocumentExtension class. This is used to validate if a glTF file with required extensions can be loaded. GetSupportedExtensions() []string // Part of the import process. This method is run after [Interface.GetSupportedExtensions] and before [Interface.ImportPostParse]. // // Runs when parsing the node extensions of a GLTFNode. This method can be used to process the extension JSON data into a format that can be used by [Interface.GenerateSceneNode]. The return value should be a member of the [Error] enum. ParseNodeExtensions(state GLTFState.Instance, gltf_node GLTFNode.Instance, extensions map[string]interface{}) error // Part of the import process. This method is run after [Interface.ParseNodeExtensions] and before [Interface.ParseTextureJson]. // // Runs when parsing image data from a glTF file. The data could be sourced from a separate file, a URI, or a buffer, and then is passed as a byte array. ParseImageData(state GLTFState.Instance, image_data []byte, mime_type string, ret_image Image.Instance) error // Returns the file extension to use for saving image data into, for example, ".png". If defined, when this extension is used to handle images, and the images are saved to a separate file, the image bytes will be copied to a file with this extension. If this is set, there should be a [graphics.gd/classdb/ResourceImporter] class able to import the file. If not defined or empty, Godot will save the image into a PNG file. GetImageFileExtension() string // Part of the import process. This method is run after [Interface.ParseImageData] and before [Interface.GenerateSceneNode]. // // Runs when parsing the texture JSON from the glTF textures array. This can be used to set the source image index to use as the texture. ParseTextureJson(state GLTFState.Instance, texture_json map[string]interface{}, ret_gltf_texture GLTFTexture.Instance) error // Part of the import process. Allows GLTFDocumentExtension classes to provide mappings for JSON pointers to glTF properties, as defined by the glTF object model, to properties of nodes in the Godot scene tree. // // Returns a [graphics.gd/classdb/GLTFObjectModelProperty] instance that defines how the property should be mapped. If your extension can't handle the property, return null or an instance without any NodePaths (see [graphics.gd/classdb/GLTFObjectModelProperty.Instance.HasNodePaths]). You should use [graphics.gd/classdb/GLTFObjectModelProperty.Instance.SetTypes] to set the types, and [graphics.gd/classdb/GLTFObjectModelProperty.Instance.AppendPathToProperty] function is useful for most simple cases. // // In many cases, 'partial_paths' will contain the start of a path, allowing the extension to complete the path. For example, for /nodes/3/extensions/MY_ext/prop, Godot will pass you a NodePath that leads to node 3, so the GLTFDocumentExtension class only needs to resolve the last MY_ext/prop part of the path. In this example, the extension should check split.size() > 4 and split[0] == "nodes" and split[2] == "extensions" and split[3] == "MY_ext" at the start of the function to check if this JSON pointer applies to it, then it can use 'partial_paths' and handle split[4]. ImportObjectModelProperty(state GLTFState.Instance, split_json_pointer []string, partial_paths []string) GLTFObjectModelProperty.Instance // Part of the import process. This method is run after [Interface.ParseNodeExtensions] and before [Interface.ImportPreGenerate]. // // This method can be used to modify any of the data imported so far after parsing each node, but before generating the scene or any of its nodes. ImportPostParse(state GLTFState.Instance) error // Part of the import process. This method is run after [Interface.ImportPostParse] and before [Interface.GenerateSceneNode]. // // This method can be used to modify or read from any of the processed data structures, before generating the nodes and then running the final per-node import step. ImportPreGenerate(state GLTFState.Instance) error // Part of the import process. This method is run after [Interface.ImportPreGenerate] and before [Interface.ImportNode]. // // Runs when generating a Godot scene node from a GLTFNode. The returned node will be added to the scene tree. Multiple nodes can be generated in this step if they are added as a child of the returned node. // // Note: The 'scene_parent' parameter may be null if this is the single root node. GenerateSceneNode(state GLTFState.Instance, gltf_node GLTFNode.Instance, scene_parent Node.Instance) Node3D.Instance // Part of the import process. This method is run after [Interface.GenerateSceneNode] and before [Interface.ImportPost]. // // This method can be used to make modifications to each of the generated Godot scene nodes. ImportNode(state GLTFState.Instance, gltf_node GLTFNode.Instance, json map[string]interface{}, node Node.Instance) error // Part of the import process. This method is run last, after all other parts of the import process. // // This method can be used to modify the final Godot scene generated by the import process. ImportPost(state GLTFState.Instance, root Node.Instance) error // Part of the export process. This method is run first, before all other parts of the export process. // // The return value is used to determine if this [graphics.gd/classdb/GLTFDocumentExtension] instance should be used for exporting a given glTF file. If [Ok], the export will use this [graphics.gd/classdb/GLTFDocumentExtension] instance. If not overridden, [Ok] is returned. ExportPreflight(state GLTFState.Instance, root Node.Instance) error // Part of the export process. This method is run after [Interface.ExportPreflight] and before [Interface.ExportPostConvert]. // // Runs when converting the data from a Godot scene node. This method can be used to process the Godot scene node data into a format that can be used by [Interface.ExportNode]. ConvertSceneNode(state GLTFState.Instance, gltf_node GLTFNode.Instance, scene_node Node.Instance) // Part of the export process. This method is run after [Interface.ConvertSceneNode] and before [Interface.ExportPreserialize]. // // This method can be used to modify the converted node data structures before serialization with any additional data from the scene tree. ExportPostConvert(state GLTFState.Instance, root Node.Instance) error // Part of the export process. This method is run after [Interface.ExportPostConvert] and before [Interface.GetSaveableImageFormats]. // // This method can be used to alter the state before performing serialization. It runs every time when generating a buffer with [graphics.gd/classdb/GLTFDocument.Instance.GenerateBuffer] or writing to the file system with [graphics.gd/classdb/GLTFDocument.Instance.WriteToFilesystem]. ExportPreserialize(state GLTFState.Instance) error // Part of the export process. Allows GLTFDocumentExtension classes to provide mappings for properties of nodes in the Godot scene tree, to JSON pointers to glTF properties, as defined by the glTF object model. // // Returns a [graphics.gd/classdb/GLTFObjectModelProperty] instance that defines how the property should be mapped. If your extension can't handle the property, return null or an instance without any JSON pointers (see [graphics.gd/classdb/GLTFObjectModelProperty.Instance.HasJsonPointers]). You should use [graphics.gd/classdb/GLTFObjectModelProperty.Instance.SetTypes] to set the types, and set the JSON pointer(s) using the [graphics.gd/classdb/GLTFObjectModelProperty.Instance.JsonPointers] property. // // The parameters provide context for the property, including the NodePath, the Godot node, the GLTF node index, and the target object. The 'target_object' will be equal to 'godot_node' if no sub-object can be found, otherwise it will point to a sub-object. For example, if the path is ^"A/B/C/MeshInstance3D:mesh:surface_0/material:emission_intensity", it will get the node, then the mesh, and then the material, so 'target_object' will be the [graphics.gd/classdb/Material] resource, and 'target_depth' will be 2 because 2 levels were traversed to get to the target. ExportObjectModelProperty(state GLTFState.Instance, node_path string, godot_node Node.Instance, gltf_node_index int, target_object Object.Instance, target_depth int) GLTFObjectModelProperty.Instance // Part of the export process. This method is run after [Interface.ConvertSceneNode] and before [Interface.ExportNode]. // // Returns an array of the image formats that can be saved/exported by this extension. This extension will only be selected as the image exporter if the [graphics.gd/classdb/GLTFDocument]'s [graphics.gd/classdb/GLTFDocument.Instance.ImageFormat] is in this array. If this [graphics.gd/classdb/GLTFDocumentExtension] is selected as the image exporter, one of the [Interface.SaveImageAtPath] or [Interface.SerializeImageToBytes] methods will run next, otherwise [Interface.ExportNode] will run next. If the format name contains "Lossy", the lossy quality slider will be displayed. GetSaveableImageFormats() []string // Part of the export process. This method is run after [Interface.GetSaveableImageFormats] and before [Interface.SerializeTextureJson]. // // This method is run when embedding images in the glTF file. When images are saved separately, [Interface.SaveImageAtPath] runs instead. Note that these methods only run when this [graphics.gd/classdb/GLTFDocumentExtension] is selected as the image exporter. // // This method must set the image MIME type in the 'image_dict' with the "mimeType" key. For example, for a PNG image, it would be set to "image/png". The return value must be a []byte containing the image data. SerializeImageToBytes(state GLTFState.Instance, image Image.Instance, image_dict map[string][]uint8, image_format string, lossy_quality Float.X) []byte // Part of the export process. This method is run after [Interface.GetSaveableImageFormats] and before [Interface.SerializeTextureJson]. // // This method is run when saving images separately from the glTF file. When images are embedded, [Interface.SerializeImageToBytes] runs instead. Note that these methods only run when this [graphics.gd/classdb/GLTFDocumentExtension] is selected as the image exporter. SaveImageAtPath(state GLTFState.Instance, image Image.Instance, file_path string, image_format string, lossy_quality Float.X) error // Part of the export process. This method is run after [Interface.SaveImageAtPath] or [Interface.SerializeImageToBytes], and before [Interface.ExportNode]. Note that this method only runs when this [graphics.gd/classdb/GLTFDocumentExtension] is selected as the image exporter. // // This method can be used to set up the extensions for the texture JSON by editing 'texture_json'. The extension must also be added as used extension with [graphics.gd/classdb/GLTFState.Instance.AddUsedExtension], be sure to set required to true if you are not providing a fallback. SerializeTextureJson(state GLTFState.Instance, texture_json map[string]interface{}, gltf_texture GLTFTexture.Instance, image_format string) error // Part of the export process. This method is run after [Interface.GetSaveableImageFormats] and before [Interface.ExportPost]. If this [graphics.gd/classdb/GLTFDocumentExtension] is used for exporting images, this runs after [Interface.SerializeTextureJson]. // // This method can be used to modify the final JSON of each node. Data should be primarily stored in 'gltf_node' prior to serializing the JSON, but the original Godot [graphics.gd/classdb/Node] is also provided if available. 'node' may be null if not available, such as when exporting glTF data not generated from a Godot scene. ExportNode(state GLTFState.Instance, gltf_node GLTFNode.Instance, json map[string]interface{}, node Node.Instance) error // Part of the export process. This method is run last, after all other parts of the export process. // // This method can be used to modify the final JSON of the generated glTF file. ExportPost(state GLTFState.Instance) error }