GLTFDocument

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

GLTFDocument supports reading data from a glTF file, buffer, or Godot scene. This data can then be written to the filesystem, buffer, or used to create a Godot scene.

All of the data in a glTF scene is stored in the GLTFState class. GLTFDocument processes state objects, but does not contain any scene data itself. GLTFDocument has member variables to store export configuration settings such as the image format, but is otherwise stateless. Multiple scenes can be processed with the same settings using the same GLTFDocument object and different GLTFState objects.

GLTFDocument can be extended with arbitrary functionality by extending the GLTFDocumentExtension class and registering it with GLTFDocument via RegisterGltfDocumentExtension. This allows for custom data to be imported and exported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportObjectModelProperty

func ExportObjectModelProperty(state GLTFState.Instance, node_path string, godot_node Node.Instance, gltf_node_index int) GLTFObjectModelProperty.Instance

Determines a mapping between the given Godot 'node_path' and the corresponding glTF Object Model JSON pointer(s) in the generated glTF file. The details of this mapping are returned in a GLTFObjectModelProperty object. Additional mappings can be supplied via the GLTFDocumentExtension.ImportObjectModelProperty callback method.

func GetSupportedGltfExtensions

func GetSupportedGltfExtensions() []string

Returns a list of all support glTF extensions, including extensions supported directly by the engine, and extensions supported by user plugins registering GLTFDocumentExtension classes.

Note: If this method is run before a GLTFDocumentExtension is registered, its extensions won't be included in the list. Be sure to only run this method after all extensions are registered. If you run this when the engine starts, consider waiting a frame before calling this method to ensure all extensions are registered.

func ImportObjectModelProperty

func ImportObjectModelProperty(state GLTFState.Instance, json_pointer string) GLTFObjectModelProperty.Instance

Determines a mapping between the given glTF Object Model 'json_pointer' and the corresponding Godot node path(s) in the generated Godot scene. The details of this mapping are returned in a GLTFObjectModelProperty object. Additional mappings can be supplied via the GLTFDocumentExtension.ExportObjectModelProperty callback method.

func RegisterGltfDocumentExtension

func RegisterGltfDocumentExtension(extension GLTFDocumentExtension.Instance, first_priority bool)

Registers the given GLTFDocumentExtension instance with GLTFDocument. If 'first_priority' is true, this extension will be run first. Otherwise, it will be run last.

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 GLTFState or GLTFNode.

func UnregisterGltfDocumentExtension

func UnregisterGltfDocumentExtension(extension GLTFDocumentExtension.Instance)

Unregisters the given GLTFDocumentExtension instance.

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 Any

type Any interface {
	gd.IsClass
	AsGLTFDocument() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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

func (*Extension[T]) AsGLTFDocument

func (self *Extension[T]) AsGLTFDocument() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.GLTFDocument

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 New

func New() Instance

func (Instance) AppendFromBuffer

func (self Instance) AppendFromBuffer(bytes []byte, base_path string, state GLTFState.Instance) error

Takes a []byte defining a glTF and imports the data to the given GLTFState object through the 'state' parameter.

Note: The 'base_path' tells AppendFromBuffer where to find dependencies and can be empty.

func (Instance) AppendFromFile

func (self Instance) AppendFromFile(path string, state GLTFState.Instance) error

Takes a path to a glTF file and imports the data at that file path to the given GLTFState object through the 'state' parameter.

Note: The 'base_path' tells AppendFromFile where to find dependencies and can be empty.

func (Instance) AppendFromScene

func (self Instance) AppendFromScene(node Node.Instance, state GLTFState.Instance) error

Takes a Godot Engine scene node and exports it and its descendants to the given GLTFState object through the 'state' parameter.

func (Instance) AsGLTFDocument

func (self Instance) AsGLTFDocument() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) FallbackImageFormat

func (self Instance) FallbackImageFormat() string

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

func (Instance) FallbackImageQuality

func (self Instance) FallbackImageQuality() Float.X

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.

func (Instance) GenerateBuffer

func (self Instance) GenerateBuffer(state GLTFState.Instance) []byte

Takes a GLTFState object through the 'state' parameter and returns a glTF []byte.

func (Instance) GenerateScene

func (self Instance) GenerateScene(state GLTFState.Instance) Node.Instance

Takes a GLTFState object through the 'state' parameter and returns a Godot Engine scene node.

The 'bake_fps' parameter overrides the bake_fps in 'state'.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) ImageFormat

func (self Instance) ImageFormat() string

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.

func (Instance) LossyQuality

func (self Instance) LossyQuality() Float.X

If ImageFormat 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.

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) RootNodeMode

func (self Instance) RootNodeMode() RootNodeMode

How to process the root node during export. The default and recommended value is RootNodeModeSingleRoot.

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.

func (Instance) SetFallbackImageFormat

func (self Instance) SetFallbackImageFormat(value string)

SetFallbackImageFormat sets the property returned by [GetFallbackImageFormat].

func (Instance) SetFallbackImageQuality

func (self Instance) SetFallbackImageQuality(value Float.X)

SetFallbackImageQuality sets the property returned by [GetFallbackImageQuality].

func (Instance) SetImageFormat

func (self Instance) SetImageFormat(value string)

SetImageFormat sets the property returned by [GetImageFormat].

func (Instance) SetLossyQuality

func (self Instance) SetLossyQuality(value Float.X)

SetLossyQuality sets the property returned by [GetLossyQuality].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetRootNodeMode

func (self Instance) SetRootNodeMode(value RootNodeMode)

SetRootNodeMode sets the property returned by [GetRootNodeMode].

func (Instance) SetVisibilityMode

func (self Instance) SetVisibilityMode(value VisibilityMode)

SetVisibilityMode sets the property returned by [GetVisibilityMode].

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

func (Instance) VisibilityMode

func (self Instance) VisibilityMode() VisibilityMode

How to deal with node visibility during export. This setting does nothing if all nodes are visible. The default and recommended value is VisibilityModeIncludeRequired, which uses the KHR_node_visibility extension.

func (Instance) WriteToFilesystem

func (self Instance) WriteToFilesystem(state GLTFState.Instance, path string) error

Takes a GLTFState object through the 'state' parameter and writes a glTF file to the filesystem.

Note: The extension of the glTF file determines if it is a .glb binary file or a .gltf text file.

type MoreArgs

type MoreArgs [1]gdclass.GLTFDocument

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) AppendFromBuffer

func (self MoreArgs) AppendFromBuffer(bytes []byte, base_path string, state GLTFState.Instance, flags int) error

Takes a []byte defining a glTF and imports the data to the given GLTFState object through the 'state' parameter.

Note: The 'base_path' tells AppendFromBuffer where to find dependencies and can be empty.

func (MoreArgs) AppendFromFile

func (self MoreArgs) AppendFromFile(path string, state GLTFState.Instance, flags int, base_path string) error

Takes a path to a glTF file and imports the data at that file path to the given GLTFState object through the 'state' parameter.

Note: The 'base_path' tells AppendFromFile where to find dependencies and can be empty.

func (MoreArgs) AppendFromScene

func (self MoreArgs) AppendFromScene(node Node.Instance, state GLTFState.Instance, flags int) error

Takes a Godot Engine scene node and exports it and its descendants to the given GLTFState object through the 'state' parameter.

func (MoreArgs) GenerateScene

func (self MoreArgs) GenerateScene(state GLTFState.Instance, bake_fps Float.X, trimming bool, remove_immutable_tracks bool) Node.Instance

Takes a GLTFState object through the 'state' parameter and returns a Godot Engine scene node.

The 'bake_fps' parameter overrides the bake_fps in 'state'.

type RootNodeMode

type RootNodeMode int //gd:GLTFDocument.RootNodeMode
const (
	// 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 [RootNodeModeKeepRoot] if the implementation does not support GODOT_single_root.
	RootNodeModeSingleRoot RootNodeMode = 0
	// 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.
	RootNodeModeKeepRoot RootNodeMode = 1
	// 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.
	RootNodeModeMultiRoot RootNodeMode = 2
)

type VisibilityMode

type VisibilityMode int //gd:GLTFDocument.VisibilityMode
const (
	// 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.
	VisibilityModeIncludeRequired VisibilityMode = 0
	// 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.
	VisibilityModeIncludeOptional VisibilityMode = 1
	// 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.
	VisibilityModeExclude VisibilityMode = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL