Class GltfImport
Loads a glTF's content, converts it to Unity resources and is able to
feed it to an
Inherited Members
Namespace: GLTFast
Syntax
public class GltfImport : IGltfReadable, IGltfBuffers, IDisposable
Constructors
GltfImport(IDownloadProvider, IDeferAgent, IMaterialGenerator, ICodeLogger)
Constructs a GltfImport instance with injectable customization objects.
Declaration
public GltfImport(IDownloadProvider downloadProvider = null, IDeferAgent deferAgent = null, IMaterialGenerator materialGenerator = null, ICodeLogger logger = null)
Parameters
Type | Name | Description |
---|---|---|
IDownloadProvider | downloadProvider | Provides file access or download customization |
IDeferAgent | deferAgent | Provides custom update loop behavior for better frame rate control |
IMaterialGenerator | materialGenerator | Provides custom glTF to Unity material conversion |
ICodeLogger | logger | Provides custom message logging |
Properties
DefaultSceneIndex
Default scene index
Declaration
public int? DefaultSceneIndex { get; }
Property Value
Type | Description |
---|---|
Nullable<Int32> |
ImageCount
Number of images
Declaration
public int ImageCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Implements
LoadingDone
True, when loading has finished and glTF can be instantiated
Declaration
public bool LoadingDone { get; }
Property Value
Type | Description |
---|---|
Boolean |
LoadingError
True if an error happened during glTF loading
Declaration
public bool LoadingError { get; }
Property Value
Type | Description |
---|---|
Boolean |
MaterialCount
Number of materials
Declaration
public int MaterialCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Implements
SceneCount
Number of scenes
Declaration
public int SceneCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
TextureCount
Number of textures
Declaration
public int TextureCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Implements
Methods
Dispose()
Frees up memory by disposing all sub assets. There can be no instantiation or other element access afterwards.
Declaration
public void Dispose()
Implements
GetAccessorSparseIndices(AccessorSparseIndices, out Void*)
Get sparse indices raw data
Declaration
public void GetAccessorSparseIndices(AccessorSparseIndices sparseIndices, out void *data)
Parameters
Type | Name | Description |
---|---|---|
AccessorSparseIndices | sparseIndices | glTF sparse indices accessor |
Void* | data | Pointer to accessor's data in memory |
GetAccessorSparseValues(AccessorSparseValues, out Void*)
Get sparse value raw data
Declaration
public void GetAccessorSparseValues(AccessorSparseValues sparseValues, out void *data)
Parameters
Type | Name | Description |
---|---|---|
AccessorSparseValues | sparseValues | glTF sparse values accessor |
Void* | data | Pointer to accessor's data in memory |
GetAnimationClips()
Returns all imported animation clips
Declaration
public AnimationClip[] GetAnimationClips()
Returns
Type | Description |
---|---|
AnimationClip[] | All imported animation clips |
GetBindPoses(Int32)
Returns an array of inverse bone matrices representing a skin's bind pose suitable for use with UnityEngine.Mesh.bindposes by glTF skin index.
Declaration
public Matrix4x4[] GetBindPoses(int skinId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | skinId | glTF skin index |
Returns
Type | Description |
---|---|
Matrix4x4[] | Corresponding bind poses |
Implements
GetDefaultMaterial()
Returns a fallback material to be used when no material was assigned (provided by the IMaterialGenerator)
Declaration
public Material GetDefaultMaterial()
Returns
Type | Description |
---|---|
Material | Default material |
Implements
GetImage(Int32)
Returns a texture by its glTF image index
Declaration
public Texture2D GetImage(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF image index |
Returns
Type | Description |
---|---|
Texture2D | Corresponding Unity texture |
Implements
GetMaterial(Int32)
Get a Unity Material by its glTF material index
Declaration
public Material GetMaterial(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF material index |
Returns
Type | Description |
---|---|
Material | Corresponding Unity Material |
Implements
GetMeshes()
Returns all imported meshes
Declaration
public Mesh[] GetMeshes()
Returns
Type | Description |
---|---|
Mesh[] | All imported meshes |
GetSceneName(Int32)
Get a glTF's scene's name by its index
Declaration
public string GetSceneName(int sceneIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sceneIndex | glTF scene index |
Returns
Type | Description |
---|---|
String | Scene name or null |
GetSourceCamera(UInt32)
Get source (de-serialized glTF) camera
Declaration
public Camera GetSourceCamera(uint index)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | index | glTF camera index |
Returns
Type | Description |
---|---|
Camera | De-serialized glTF camera |
Implements
GetSourceImage(Int32)
Get source (de-serialized glTF) image
Declaration
public Image GetSourceImage(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF image index |
Returns
Type | Description |
---|---|
Image | De-serialized glTF image |
Implements
GetSourceLightPunctual(UInt32)
Get source (de-serialized glTF) light
Declaration
public LightPunctual GetSourceLightPunctual(uint index)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | index | glTF light index |
Returns
Type | Description |
---|---|
LightPunctual | De-serialized glTF light |
Implements
GetSourceMaterial(Int32)
Get source (de-serialized glTF) material
Declaration
public Material GetSourceMaterial(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF material index |
Returns
Type | Description |
---|---|
Material | De-serialized glTF material |
Implements
GetSourceNode(Int32)
Get source (de-serialized glTF) node
Declaration
public Node GetSourceNode(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF node index |
Returns
Type | Description |
---|---|
Node | De-serialized glTF node |
Implements
GetSourceRoot()
Get source root (de-serialized glTF JSON). This is intended for read-only access. Changes might corrupt data and break subsequent scene instantiation.
Declaration
public Root GetSourceRoot()
Returns
Type | Description |
---|---|
Root | De-serialized glTF root object |
Implements
GetSourceScene(Int32)
Get source (de-serialized glTF) scene
Declaration
public Scene GetSourceScene(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF scene index |
Returns
Type | Description |
---|---|
Scene | De-serialized glTF scene |
Implements
GetSourceTexture(Int32)
Get source (de-serialized glTF) texture
Declaration
public Texture GetSourceTexture(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF texture index |
Returns
Type | Description |
---|---|
Texture | De-serialized glTF texture |
Implements
GetTexture(Int32)
Returns a texture by its glTF texture index
Declaration
public Texture2D GetTexture(int index = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | glTF texture index |
Returns
Type | Description |
---|---|
Texture2D | Corresponding Unity texture |
Implements
InstantiateMainScene(IInstantiator)
Creates an instance of the main scene of the glTF ( "scene" property in the JSON at root level; DefaultSceneIndex) If the main scene index is not set, it instantiates nothing (as defined in the glTF 2.0 specification)
Declaration
[Obsolete("Use InstantiateMainSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
public bool InstantiateMainScene(IInstantiator instantiator)
Parameters
Type | Name | Description |
---|---|---|
IInstantiator | instantiator |
Returns
Type | Description |
---|---|
Boolean | True if the main scene was instantiated or was not set. False in case of errors. |
InstantiateMainScene(Transform)
Creates an instance of the main scene of the glTF ( "scene" property in the JSON at root level; DefaultSceneIndex) If the main scene index is not set, it instantiates nothing (as defined in the glTF 2.0 specification)
Declaration
[Obsolete("Use InstantiateMainSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
public bool InstantiateMainScene(Transform parent)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent |
Returns
Type | Description |
---|---|
Boolean | True if the main scene was instantiated or was not set. False in case of errors. |
InstantiateMainSceneAsync(IInstantiator, CancellationToken)
Creates an instance of the main scene of the glTF ( "scene" property in the JSON at root level; DefaultSceneIndex) If the main scene index is not set, it instantiates nothing (as defined in the glTF 2.0 specification)
Declaration
public async Task<bool> InstantiateMainSceneAsync(IInstantiator instantiator, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IInstantiator | instantiator | Instantiator implementation; Receives and processes the scene data |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if the main scene was instantiated or was not set. False in case of errors. |
InstantiateMainSceneAsync(Transform, CancellationToken)
Creates an instance of the main scene of the glTF ( "scene" property in the JSON at root level; DefaultSceneIndex) If the main scene index is not set, it instantiates nothing (as defined in the glTF 2.0 specification)
Declaration
public async Task<bool> InstantiateMainSceneAsync(Transform parent, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | Transform that the scene will get parented to |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if the main scene was instantiated or was not set. False in case of errors. |
InstantiateScene(IInstantiator, Int32)
Creates an instance of the scene specified by the scene index. SceneCount GetSceneName(Int32)
Declaration
[Obsolete("Use InstantiateSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
public bool InstantiateScene(IInstantiator instantiator, int sceneIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
IInstantiator | instantiator | |
Int32 | sceneIndex |
Returns
Type | Description |
---|---|
Boolean | True if the scene was instantiated. False in case of errors. |
InstantiateScene(Transform, Int32)
Creates an instance of the scene specified by the scene index. SceneCount GetSceneName(Int32)
Declaration
[Obsolete("Use InstantiateSceneAsync for increased performance and safety. Consult the Upgrade Guide for instructions.")]
public bool InstantiateScene(Transform parent, int sceneIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | |
Int32 | sceneIndex |
Returns
Type | Description |
---|---|
Boolean | True if the scene was instantiated. False in case of errors. |
InstantiateSceneAsync(IInstantiator, Int32, CancellationToken)
Creates an instance of the scene specified by the scene index. SceneCount GetSceneName(Int32)
Declaration
public async Task<bool> InstantiateSceneAsync(IInstantiator instantiator, int sceneIndex = 0, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IInstantiator | instantiator | Instantiator implementation; Receives and processes the scene data |
Int32 | sceneIndex | Index of the scene to be instantiated |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if the scene was instantiated. False in case of errors. |
InstantiateSceneAsync(Transform, Int32, CancellationToken)
Creates an instance of the scene specified by the scene index. SceneCount GetSceneName(Int32)
Declaration
public async Task<bool> InstantiateSceneAsync(Transform parent, int sceneIndex = 0, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Transform | parent | Transform that the scene will get parented to |
Int32 | sceneIndex | Index of the scene to be instantiated |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if the scene was instantiated. False in case of errors. |
Load(Byte[], Uri, ImportSettings, CancellationToken)
Load a glTF from a byte array. If the type (JSON or glTF-Binary) is know, LoadGltfJson(String, Uri, ImportSettings, CancellationToken) and LoadGltfBinary(Byte[], Uri, ImportSettings, CancellationToken) should be preferred.
Declaration
public async Task<bool> Load(byte[] data, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Byte[] | data | Either glTF-Binary data or a glTF JSON |
Uri | uri | Base URI for relative paths of external buffers or images |
ImportSettings | importSettings | Import Settings (ImportSettings for details) |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if loading was successful, false otherwise |
Load(String, ImportSettings, CancellationToken)
Load a glTF file (JSON or binary) The URL can be a file path (using the "file://" scheme) or a web address.
Declaration
public async Task<bool> Load(string url, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | url | Uniform Resource Locator. Can be a file path (using the "file://" scheme) or a web address. |
ImportSettings | importSettings | Import Settings (ImportSettings for details) |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if loading was successful, false otherwise |
Load(Uri, ImportSettings, CancellationToken)
Load a glTF file (JSON or binary) The URL can be a file path (using the "file://" scheme) or a web address.
Declaration
public async Task<bool> Load(Uri url, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Uri | url | Uniform Resource Locator. Can be a file path (using the "file://" scheme) or a web address. |
ImportSettings | importSettings | Import Settings (ImportSettings for details) |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if loading was successful, false otherwise |
LoadFile(String, Uri, ImportSettings, CancellationToken)
Load glTF from a local file path.
Declaration
public async Task<bool> LoadFile(string localPath, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | localPath | Local path to glTF or glTF-Binary file. |
Uri | uri | Base URI for relative paths of external buffers or images |
ImportSettings | importSettings | Import Settings (ImportSettings for details) |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if loading was successful, false otherwise |
LoadGltfBinary(Byte[], Uri, ImportSettings, CancellationToken)
Load a glTF-binary asset from a byte array.
Declaration
public async Task<bool> LoadGltfBinary(byte[] bytes, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Byte[] | bytes | byte array containing glTF-binary |
Uri | uri | Base URI for relative paths of external buffers or images |
ImportSettings | importSettings | Import Settings (ImportSettings for details) |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if loading was successful, false otherwise |
LoadGltfJson(String, Uri, ImportSettings, CancellationToken)
Load a glTF JSON from a string
Declaration
public async Task<bool> LoadGltfJson(string json, Uri uri = null, ImportSettings importSettings = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | json | glTF JSON |
Uri | uri | Base URI for relative paths of external buffers or images |
ImportSettings | importSettings | Import Settings (ImportSettings for details) |
CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Boolean> | True if loading was successful, false otherwise |
SetDefaultDeferAgent(IDeferAgent)
Sets the default IDeferAgent for subsequently generated GltfImport instances.
Declaration
public static void SetDefaultDeferAgent(IDeferAgent deferAgent)
Parameters
Type | Name | Description |
---|---|---|
IDeferAgent | deferAgent | New default IDeferAgent |
UnsetDefaultDeferAgent(IDeferAgent)
Allows un-registering default IDeferAgent. For example if it's no longer available.
Declaration
public static void UnsetDefaultDeferAgent(IDeferAgent deferAgent)
Parameters
Type | Name | Description |
---|---|---|
IDeferAgent | deferAgent | IDeferAgent in question |