GltfDocument
Class for importing and exporting glTF files in and out of Reckfell.
Class for importing and exporting glTF files in and out of Reckfell.
GLTFDocument supports reading data from a glTF file, buffer, or Reckfell scene. This data can then be written to the filesystem, buffer, or used to create a Reckfell 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 GltfDocument.RegisterGltfDocumentExtension. This allows for custom data to be imported and exported.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
GltfDocumentConstructor
public GltfDocument();Properties7
FallbackImageFormatProperty
public string FallbackImageFormat { get; set; }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 GltfDocument.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.
FallbackImageQualityProperty
public float FallbackImageQuality { get; set; }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.
ImageFormatProperty
public string ImageFormat { get; set; }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, Reckfell 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.
LossyQualityProperty
public float LossyQuality { get; set; }If GltfDocument.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.
RootNodeModeProperty
public GltfDocument.RootNodeModeEnum RootNodeMode { get; set; }How to process the root node during export. The default and recommended value is GltfDocument.RootNodeModeEnum.SingleRoot.
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.
TextureMapModeProperty
public GltfDocument.TextureMapModeEnum TextureMapMode { get; set; }How to handle texture maps during import. The default and recommended value is GltfDocument.TextureMapModeEnum.RemapToStandardMaterial, which automatically remaps from glTF's flexible texture map system to the more specific texture map slots in Reckfell's StandardMaterial3D class. Alternatively, GltfDocument.TextureMapModeEnum.DoNotRemap can be used to preserve the original texture maps from the glTF file, which may be desirable if using the glTF file with custom shaders, but may not display correctly with Reckfell's built-in materials.
VisibilityModeProperty
public GltfDocument.VisibilityModeEnum VisibilityMode { get; set; }How to deal with node visibility during export. This setting does nothing if all nodes are visible. The default and recommended value is GltfDocument.VisibilityModeEnum.IncludeRequired, which uses the KHR_node_visibility extension.
Methods26
AppendFromBuffer2 overloads
public Error AppendFromBuffer(byte[] bytes, string basePath, GltfState state, uint flags = 0);Takes a byte[] defining a glTF and imports the data to the given GltfState object through the state parameter.
Note: The base_path tells GltfDocument.AppendFromBuffer where to find dependencies and can be empty.
| Name | Type | Default |
|---|---|---|
bytes | byte[] | — |
basePath | string | — |
state | GltfState | — |
flags | uint | 0 |
Errorpublic Error AppendFromBuffer(ReadOnlySpan<byte> bytes, string basePath, GltfState state, uint flags);Takes a byte[] defining a glTF and imports the data to the given GltfState object through the state parameter.
Note: The base_path tells GltfDocument.AppendFromBuffer where to find dependencies and can be empty.
| Name | Type | Default |
|---|---|---|
bytes | ReadOnlySpan<byte> | — |
basePath | string | — |
state | GltfState | — |
flags | uint | — |
ErrorAppendFromFileError
public Error AppendFromFile(string path, GltfState state, uint flags = 0, string basePath = "");Reads glTF/GLB into GltfState, resolving dependencies relative to basePath. Does not create the Entity tree yet: call GenerateScene after Error.Ok. Use a fresh state for independent loading. Not a universal FBX, Blender or Reckfell project loader.
| Name | Type | Default |
|---|---|---|
path | string | — |
state | GltfState | — |
flags | uint | 0 |
basePath | string | "" |
pathInput glTF/GLB file path through FileAccess. Neighboring buffers and images must be available.
stateglTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.
flagsGltfDocument.ImportFlags bitmask passed as uint; 0 leaves these extra flags disabled. Not renderer-quality settings.
basePathBase directory for external images and buffers. Empty uses the directory of path; do not pass an individual texture path here.
ErrorError.Ok when this stage succeeds; otherwise an error code. Does not establish visual identity or complete transfer of every feature.
AppendFromSceneError
public Error AppendFromScene(Entity node, GltfState state, uint flags = 0);Converts the supplied Entity root and descendants into GltfState data. Does not write a file or free the source tree. For independent export, use a fresh state, then call WriteToFilesystem. Successful conversion does not guarantee transfer of ShaderMaterial or gameplay features.
| Name | Type | Default |
|---|---|---|
node | Entity | — |
state | GltfState | — |
flags | uint | 0 |
nodeLive root of the exported tree. The C# parameter is named node and has type Entity; the parameter name does not change the engine object model.
stateglTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.
flagsGltfDocument.ImportFlags bitmask passed as uint; 0 leaves these extra flags disabled. Not renderer-quality settings.
ErrorError.Ok when this stage succeeds; otherwise an error code. Does not establish visual identity or complete transfer of every feature.
ExportObjectModelPropertyGltfObjectModelProperty
public static GltfObjectModelProperty ExportObjectModelProperty(GltfState state, EntityPath entityPath, Entity reckfellNode, int gltfNodeIndex);Determines a mapping between the given Reckfell entity_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.
| Name | Type | Default |
|---|---|---|
state | GltfState | — |
entityPath | EntityPath | — |
reckfellNode | Entity | — |
gltfNodeIndex | int | — |
GltfObjectModelPropertyGenerateBufferbyte[]
public byte[] GenerateBuffer(GltfState state);Takes a GltfState object through the state parameter and returns a glTF byte[].
| Name | Type | Default |
|---|---|---|
state | GltfState | — |
byte[]GenerateSceneEntity
public Entity GenerateScene(GltfState state, float bakeFps = 30f, bool trimming = false, bool removeImmutableTracks = true);Creates an Entity tree from a prepared GltfState. Does not automatically add it to EntityTree; attach explicitly or release with Free. bakeFps replaces the state bake rate. Animation creation also depends on state data and settings.
| Name | Type | Default |
|---|---|---|
state | GltfState | — |
bakeFps | float | 30f |
trimming | bool | false |
removeImmutableTracks | bool | true |
stateglTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.
bakeFpsImported animation bake rate; supply a positive value. Defaults to 30; does not set game rendering FPS.
trimmingTrim the imported animation range to key times instead of retaining a start at zero. Does not change geometry.
removeImmutableTracksWhen true, omit eligible transform tracks whose values all match the object base transform. Does not promise removal of every constant track of arbitrary type.
EntityRoot of the new Entity tree, or null on failure. Not a PackedEntity or an automatically active level.
GetFallbackImageFormatstring
public string GetFallbackImageFormat();stringGetFallbackImageQualityfloat
public float GetFallbackImageQuality();floatGetImageFormatstring
public string GetImageFormat();stringGetLossyQualityfloat
public float GetLossyQuality();floatGetRootEntityModeGltfDocument.RootNodeModeEnum
public GltfDocument.RootNodeModeEnum GetRootEntityMode();GltfDocument.RootNodeModeEnumGetSupportedGltfExtensionsstring[]
public static string[] GetSupportedGltfExtensions();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.
string[]GetTextureMapModeGltfDocument.TextureMapModeEnum
public GltfDocument.TextureMapModeEnum GetTextureMapMode();GltfDocument.TextureMapModeEnumGetVisibilityModeGltfDocument.VisibilityModeEnum
public GltfDocument.VisibilityModeEnum GetVisibilityMode();GltfDocument.VisibilityModeEnumImportObjectModelPropertyGltfObjectModelProperty
public static GltfObjectModelProperty ImportObjectModelProperty(GltfState state, string jsonPointer);Determines a mapping between the given glTF Object Model json_pointer and the corresponding Reckfell node path(s) in the generated Reckfell scene. The details of this mapping are returned in a GltfObjectModelProperty object. Additional mappings can be supplied via the GltfDocumentExtension._ExportObjectModelProperty callback method.
| Name | Type | Default |
|---|---|---|
state | GltfState | — |
jsonPointer | string | — |
GltfObjectModelPropertyRegisterGltfDocumentExtensionvoid
public static void RegisterGltfDocumentExtension(GltfDocumentExtension extension, bool firstPriority = false);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.
| Name | Type | Default |
|---|---|---|
extension | GltfDocumentExtension | — |
firstPriority | bool | false |
SetFallbackImageFormatvoid
public void SetFallbackImageFormat(string fallbackImageFormat);| Name | Type | Default |
|---|---|---|
fallbackImageFormat | string | — |
SetFallbackImageQualityvoid
public void SetFallbackImageQuality(float fallbackImageQuality);| Name | Type | Default |
|---|---|---|
fallbackImageQuality | float | — |
SetImageFormatvoid
public void SetImageFormat(string imageFormat);| Name | Type | Default |
|---|---|---|
imageFormat | string | — |
SetLossyQualityvoid
public void SetLossyQuality(float lossyQuality);| Name | Type | Default |
|---|---|---|
lossyQuality | float | — |
SetRootEntityModevoid
public void SetRootEntityMode(GltfDocument.RootNodeModeEnum rootNodeMode);| Name | Type | Default |
|---|---|---|
rootNodeMode | GltfDocument.RootNodeModeEnum | — |
SetTextureMapModevoid
public void SetTextureMapMode(GltfDocument.TextureMapModeEnum textureMapMode);| Name | Type | Default |
|---|---|---|
textureMapMode | GltfDocument.TextureMapModeEnum | — |
SetVisibilityModevoid
public void SetVisibilityMode(GltfDocument.VisibilityModeEnum visibilityMode);| Name | Type | Default |
|---|---|---|
visibilityMode | GltfDocument.VisibilityModeEnum | — |
UnregisterGltfDocumentExtensionvoid
public static void UnregisterGltfDocumentExtension(GltfDocumentExtension extension);Unregisters the given GltfDocumentExtension instance.
| Name | Type | Default |
|---|---|---|
extension | GltfDocumentExtension | — |
WriteToFilesystemError
public Error WriteToFilesystem(GltfState state, string path);Serializes a prepared GltfState and writes a glTF file. Use .glb for a binary container or .gltf for JSON with dependencies. The parent directory must exist. Can write several files; failure does not automatically roll back partial output.
| Name | Type | Default |
|---|---|---|
state | GltfState | — |
path | string | — |
stateglTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.
pathOutput glTF/GLB file path, not a directory. Check directory access and retain generated dependency files.
ErrorError.Ok when this stage succeeds; otherwise an error code. Does not establish visual identity or complete transfer of every feature.
GltfDocument.ImportFlags
| Value | Description |
|---|---|
DiscardMeshesAndMaterials = 32 | Ignore meshes and materials on import. When importing a scene as an |
ForceDisableMeshCompression = 64 | If |
GenerateTangentArrays = 8 | If |
UseNamedSkinBinds = 16 | If checked, use named
|
GltfDocument.RootNodeModeEnum
| Value | Description |
|---|---|
KeepRoot = 1 | Treat the Reckfell 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 Reckfell. This uses only vanilla glTF features. This is equivalent to the behavior in Reckfell and earlier. |
MultiRoot = 2 | Treat the Reckfell 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 Reckfell scene's root node will be preserved, as it will not be saved as a node. |
SingleRoot = 0 | Treat the Reckfell scene's root node as the root node of the glTF file, and mark it as the single root node via the |
GltfDocument.TextureMapModeEnum
| Value | Description |
|---|---|
DoNotRemap = 0 | Import the texture maps in the glTF file as they are, without trying to fit them into specific texture slots suitable for Reckfell's built-in materials. This may be desirable if using the glTF file with custom shaders, but may not display correctly with Reckfell's built-in materials. This is equivalent to the behavior in Reckfell and earlier. |
RemapToStandardMaterial = 1 | Import the texture maps in the glTF file remapped to the most suitable texture slots based on Reckfell's |
GltfDocument.VisibilityModeEnum
| Value | Description |
|---|---|
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 Reckfell and earlier. Downside: Invisible nodes will not exist in the exported file. |
IncludeOptional = 1 | If the scene contains any non-visible nodes, include them, mark them as non-visible with |
IncludeRequired = 0 | If the scene contains any non-visible nodes, include them, mark them as non-visible with |