reckfellENGINE

GltfDocument

Class for importing and exporting glTF files in and out of Reckfell.

On this page
class GltfDocumentReckfellSharpInherits Resource

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
# GltfDocument
C#
public GltfDocument();

Properties7

FallbackImageFormatProperty
# FallbackImageFormat
C#
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
# FallbackImageQuality
C#
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
# ImageFormat
C#
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
# LossyQuality
C#
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
# RootNodeMode
C#
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
# TextureMapMode
C#
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
# VisibilityMode
C#
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
# AppendFromBuffer · 1/2
C#
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.

Parameters
NameTypeDefault
bytesbyte[]—
basePathstring—
stateGltfState—
flagsuint0
Returns Error
# AppendFromBuffer · 2/2
C#
public 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.

Parameters
NameTypeDefault
bytesReadOnlySpan<byte>—
basePathstring—
stateGltfState—
flagsuint—
Returns Error
AppendFromFileError
# AppendFromFile
C#
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.

Parameters
NameTypeDefault
pathstring—
stateGltfState—
flagsuint0
basePathstring""
path

Input glTF/GLB file path through FileAccess. Neighboring buffers and images must be available.

state

glTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.

flags

GltfDocument.ImportFlags bitmask passed as uint; 0 leaves these extra flags disabled. Not renderer-quality settings.

basePath

Base directory for external images and buffers. Empty uses the directory of path; do not pass an individual texture path here.

Returns Error

Error.Ok when this stage succeeds; otherwise an error code. Does not establish visual identity or complete transfer of every feature.

AppendFromSceneError
# AppendFromScene
C#
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.

Parameters
NameTypeDefault
nodeEntity—
stateGltfState—
flagsuint0
node

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

state

glTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.

flags

GltfDocument.ImportFlags bitmask passed as uint; 0 leaves these extra flags disabled. Not renderer-quality settings.

Returns Error

Error.Ok when this stage succeeds; otherwise an error code. Does not establish visual identity or complete transfer of every feature.

ExportObjectModelPropertyGltfObjectModelProperty
# ExportObjectModelProperty
C#
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.

Parameters
NameTypeDefault
stateGltfState—
entityPathEntityPath—
reckfellNodeEntity—
gltfNodeIndexint—
Returns GltfObjectModelProperty
GenerateBufferbyte[]
# GenerateBuffer
C#
public byte[] GenerateBuffer(GltfState state);

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

Parameters
NameTypeDefault
stateGltfState—
Returns byte[]
GenerateSceneEntity
# GenerateScene
C#
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.

Parameters
NameTypeDefault
stateGltfState—
bakeFpsfloat30f
trimmingboolfalse
removeImmutableTracksbooltrue
state

glTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.

bakeFps

Imported animation bake rate; supply a positive value. Defaults to 30; does not set game rendering FPS.

trimming

Trim the imported animation range to key times instead of retaining a start at zero. Does not change geometry.

removeImmutableTracks

When true, omit eligible transform tracks whose values all match the object base transform. Does not promise removal of every constant track of arbitrary type.

Returns Entity

Root of the new Entity tree, or null on failure. Not a PackedEntity or an automatically active level.

GetFallbackImageFormatstring
# GetFallbackImageFormat
C#
public string GetFallbackImageFormat();
Returns string
GetFallbackImageQualityfloat
# GetFallbackImageQuality
C#
public float GetFallbackImageQuality();
Returns float
GetImageFormatstring
# GetImageFormat
C#
public string GetImageFormat();
Returns string
GetLossyQualityfloat
# GetLossyQuality
C#
public float GetLossyQuality();
Returns float
GetRootEntityModeGltfDocument.RootNodeModeEnum
# GetRootEntityMode
C#
public GltfDocument.RootNodeModeEnum GetRootEntityMode();
Returns GltfDocument.RootNodeModeEnum
GetSupportedGltfExtensionsstring[]
# GetSupportedGltfExtensions
C#
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.

Returns string[]
GetTextureMapModeGltfDocument.TextureMapModeEnum
# GetTextureMapMode
C#
public GltfDocument.TextureMapModeEnum GetTextureMapMode();
Returns GltfDocument.TextureMapModeEnum
GetVisibilityModeGltfDocument.VisibilityModeEnum
# GetVisibilityMode
C#
public GltfDocument.VisibilityModeEnum GetVisibilityMode();
Returns GltfDocument.VisibilityModeEnum
ImportObjectModelPropertyGltfObjectModelProperty
# ImportObjectModelProperty
C#
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.

Parameters
NameTypeDefault
stateGltfState—
jsonPointerstring—
Returns GltfObjectModelProperty
RegisterGltfDocumentExtensionvoid
# RegisterGltfDocumentExtension
C#
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.

Parameters
NameTypeDefault
extensionGltfDocumentExtension—
firstPriorityboolfalse
SetFallbackImageFormatvoid
# SetFallbackImageFormat
C#
public void SetFallbackImageFormat(string fallbackImageFormat);
Parameters
NameTypeDefault
fallbackImageFormatstring—
SetFallbackImageQualityvoid
# SetFallbackImageQuality
C#
public void SetFallbackImageQuality(float fallbackImageQuality);
Parameters
NameTypeDefault
fallbackImageQualityfloat—
SetImageFormatvoid
# SetImageFormat
C#
public void SetImageFormat(string imageFormat);
Parameters
NameTypeDefault
imageFormatstring—
SetLossyQualityvoid
# SetLossyQuality
C#
public void SetLossyQuality(float lossyQuality);
Parameters
NameTypeDefault
lossyQualityfloat—
SetRootEntityModevoid
# SetRootEntityMode
C#
public void SetRootEntityMode(GltfDocument.RootNodeModeEnum rootNodeMode);
Parameters
NameTypeDefault
rootNodeModeGltfDocument.RootNodeModeEnum—
SetTextureMapModevoid
# SetTextureMapMode
C#
public void SetTextureMapMode(GltfDocument.TextureMapModeEnum textureMapMode);
Parameters
NameTypeDefault
textureMapModeGltfDocument.TextureMapModeEnum—
SetVisibilityModevoid
# SetVisibilityMode
C#
public void SetVisibilityMode(GltfDocument.VisibilityModeEnum visibilityMode);
Parameters
NameTypeDefault
visibilityModeGltfDocument.VisibilityModeEnum—
UnregisterGltfDocumentExtensionvoid
# UnregisterGltfDocumentExtension
C#
public static void UnregisterGltfDocumentExtension(GltfDocumentExtension extension);

Unregisters the given GltfDocumentExtension instance.

Parameters
NameTypeDefault
extensionGltfDocumentExtension—
WriteToFilesystemError
# WriteToFilesystem
C#
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.

Parameters
NameTypeDefault
stateGltfState—
pathstring—
state

glTF state for this operation. Create a fresh one for reading/conversion; pass a populated one for writing/generation.

path

Output glTF/GLB file path, not a directory. Check directory access and retain generated dependency files.

Returns Error

Error.Ok when this stage succeeds; otherwise an error code. Does not establish visual identity or complete transfer of every feature.

GltfDocument.ImportFlags

ValueDescription
DiscardMeshesAndMaterials = 32

Ignore meshes and materials on import. When importing a scene as an AnimationLibrary, this flag is always enabled.

ForceDisableMeshCompression = 64

If true, mesh compression will not be used. Consider enabling if you notice blocky artifacts in your mesh normals or UVs, or if you have meshes that are larger than a few thousand meters in each direction.

GenerateTangentArrays = 8

If true, generate vertex tangents using Mikktspace(http://www.mikktspace.com/) if the input meshes don't have tangent data. When possible, it's recommended to let the 3D modeling software generate tangents on export instead of relying on this option. Tangents are required for correct display of normal and height maps, along with any material/shader features that require tangents. If you don't need material features that require tangents, disabling this can reduce output file size and speed up importing if the source 3D file doesn't contain tangents.

UseNamedSkinBinds = 16

If checked, use named Skins for animation. The MeshInstance3D node contains 3 properties of relevance here: a skeleton EntityPath pointing to the Skeleton3D node (usually ..), a mesh, and a skin:

  • The Skeleton3D node contains a list of bones with names, their pose and rest, a name, and a parent bone.
  • The mesh is all of the raw vertex data needed to display a mesh. In terms of the mesh, it knows how vertices are weight-painted and uses some internal numbering often imported from 3D modeling software.
  • The skin contains the information necessary to bind this mesh onto this Skeleton3D. For each of the internal bone IDs chosen by the 3D modeling software, it contains two things. Firstly, a matrix known as the Bind Pose Matrix, Inverse Bind Matrix, or IBM for short. Secondly, the Skin contains each bone's name (if this flag is enabled), or the bone's index within the Skeleton3D list (if this flag is disabled). Together, this information is enough to tell Reckfell how to use the bone poses in the Skeleton3D node to render the mesh from each MeshInstance3D. Note that each MeshInstance3D may share binds, as is common in models exported from Blender, or each MeshInstance3D may use a separate Skin object, as is common in models exported from other tools such as Maya.

GltfDocument.RootNodeModeEnum

ValueDescription
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 RECKFELL_single_root glTF extension. This will be parsed the same as GltfDocument.RootNodeModeEnum.KeepRoot if the implementation does not support RECKFELL_single_root.

GltfDocument.TextureMapModeEnum

ValueDescription
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 StandardMaterial3D class. This is the default behavior.

GltfDocument.VisibilityModeEnum

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

IncludeRequired = 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.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.