TriLib  1.8.7f
TriLib Unity Package
TriLib.AssetLoader Class Reference

Represents a synchronous asset loader. More...

Inheritance diagram for TriLib.AssetLoader:
TriLib.AssetLoaderBase

Public Member Functions

GameObject LoadFromFile (string filename, AssetLoaderOptions options=null, GameObject wrapperGameObject=null, string basePath=null, AssimpInterop.ProgressCallback progressCallback=null)
 Loads a UnityEngine.GameObject from input filename with defined options. More...
 
GameObject LoadFromMemory (byte[] fileBytes, string filename, AssetLoaderOptions options=null, GameObject wrapperGameObject=null, string basePath=null, AssimpInterop.DataCallback dataCallback=null, AssimpInterop.ExistsCallback existsCallback=null, LoadTextureDataCallback loadTextureDataCallback=null, AssimpInterop.ProgressCallback progressCallback=null)
 Loads a UnityEngine.GameObject from input byte array with defined options. More...
 
GameObject LoadFromFileWithTextures (string filename, AssetLoaderOptions options=null, GameObject wrapperGameObject=null, string basePath=null, AssimpInterop.ProgressCallback progressCallback=null)
 Loads a UnityEngine.GameObject from file (Accept ZIP files). More...
 
GameObject LoadFromMemoryWithTextures (byte[] fileData, string assetExtension, AssetLoaderOptions options=null, GameObject wrapperGameObject=null, string basePath=null, AssimpInterop.DataCallback dataCallback=null, AssimpInterop.ExistsCallback existsCallback=null, AssimpInterop.ProgressCallback progressCallback=null)
 Loads a UnityEngine.GameObject from input byte array (Accept ZIP files). More...
 
- Public Member Functions inherited from TriLib.AssetLoaderBase
EmbeddedTextureData LoadTextureData (string path, string basePath)
 Tries to load texture data from the given path, searching from basePath. More...
 
void Dispose ()
 

Additional Inherited Members

- Static Public Member Functions inherited from TriLib.AssetLoaderBase
static bool IsExtensionSupported (string extension)
 Checks whether the given file extension is supported. More...
 
static string GetSupportedFileExtensions ()
 Returns a string of supported file extensions. More...
 
- Static Public Attributes inherited from TriLib.AssetLoaderBase
static ConcurrentList< FileLoadData > FilesLoadData = new ConcurrentList<FileLoadData>()
 Stores a FileLoadData reference list for callbacks. More...
 
- Protected Member Functions inherited from TriLib.AssetLoaderBase
void TriggerOnMeshCreated (uint meshIndex, Mesh mesh)
 Triggers the on mesh created event. More...
 
void TriggerOnMaterialCreated (uint materialIndex, bool isOverriden, Material material)
 Triggers the on material created event. More...
 
void TriggerOnTextureLoaded (string sourcePath, Material material, string propertyName, Texture2D texture)
 Triggers the on texture loaded event. More...
 
void TriggerOnAnimationClipCreated (uint animationClipIndex, AnimationClip animationClip)
 Triggers the on animation clip created event. More...
 
void TriggerOnObjectLoaded (GameObject loadedGameObject)
 Triggers the on object loaded event. More...
 
void TriggerOnMetadataProcessed (AssimpMetadataType metadataType, uint metadataIndex, string metadataKey, object metadataValue)
 Triggers the on metadata processed event. More...
 
void TriggerOnBlendShapeKeyCreated (Mesh mesh, string name, Vector3[] vertices, Vector3[] normals, Vector4[] tangents, Vector4[] biTangents)
 Triggers the on blend-shape key created event. More...
 
void InternalLoadFromMemory (byte[] fileBytes, string filename, string basePath, AssetLoaderOptions options=null, bool usesWrapperGameObject=false, AssimpInterop.DataCallback dataCallback=null, AssimpInterop.ExistsCallback existsCallback=null, LoadTextureDataCallback loadTextureDataCallback=null, AssimpInterop.ProgressCallback progressCallback=null, FileLoadData customFileLoadData=null)
 Internally loads a file from memory into its data representation. More...
 
void InternalLoadFromMemoryAndZip (byte[] data, string assetExtension, string basePath, AssetLoaderOptions options=null, bool usesWrapperGameObject=false, AssimpInterop.DataCallback dataCallback=null, AssimpInterop.ExistsCallback existsCallback=null, LoadTextureDataCallback loadTextureDataCallback=null, AssimpInterop.ProgressCallback progressCallback=null)
 Internally loads a model from memory with custom embedded texture loading for ZIP files. More...
 
void InternalLoadFromFile (string filename, string basePath, AssetLoaderOptions options=null, bool usesWrapperGameObject=false, AssimpInterop.ProgressCallback progressCallback=null)
 Internally loads a file from file system into it's data representation. More...
 
GameObject BuildGameObject (AssetLoaderOptions options, string basePath=null, GameObject wrapperGameObject=null)
 Builds the UnityEngine.GameObject from pre-loaded data. More...
 
virtual void SetupSkinnedMeshRendererTransforms (GameObject gameObject)
 Setups the UnityEngine.SkinnedMeshRenderer bone transforms. More...
 
virtual void ProcessMetadata (AssimpMetadata metadata)
 Processes the given metadata by triggering the OnMetadataProcessed event. More...
 
virtual void SetupAnimations (GameObject gameObject, AssetLoaderOptions options)
 Setups animation components and UnityEngine.AnimationClip clips into the given UnityEngine.GameObject. More...
 
virtual GameObject TransformNodeData (NodeData nodeData, AssetLoaderOptions options, GameObject existingGameObject=null)
 Transforms given TriLib.NodeData into a UnityEngine.GameObject. More...
 
virtual void CreateMeshComponents (GameObject gameObject, AssetLoaderOptions options, Mesh mesh, bool hasBoneInfo, Material[] combinedMaterials, IList< string > boneNames=null, Material singleMaterial=null, MeshData meshData=null, string connectionKey=null)
 Creates mesh rendering components into given UnityEngine.GameObject. More...
 
virtual void TransformCameraData (GameObject gameObject, CameraData cameraData, AssetLoaderOptions options)
 Transforms the given TriLib.CameraData into a UnityEngine.Camera. More...
 
virtual void TransformAnimationData (AnimationData animationData, AssetLoaderOptions options, GameObject gameObject)
 Transforms the given TriLib.AnimationData into a UnityEngine.AnimationClip. More...
 
virtual void TransformMeshData (MeshData meshData, AssetLoaderOptions options)
 Transforms the given TriLib.MeshData into a UnityEngine.Mesh. More...
 
virtual void TransformMaterialData (MaterialData materialData, AssetLoaderOptions options, string basePath=null)
 Transforms the given TriLib.MaterialData into a UnityEngine.Material. More...
 
virtual Material LoadMaterial (string name, AssetLoaderOptions options, bool hasAlpha, bool hasSpecular)
 Creates a new UnityEngine.Material or loads an existing UnityEngine.Material with the given name. More...
 
virtual Texture2D LoadTextureFromFile (string path, string name, AssetLoaderOptions options, EmbeddedTextureData embeddedTextureData, TextureWrapMode textureWrapMode, ref bool hasAlphaChannel, bool isNormalMap, bool checkAlphaChannel=false)
 Creates a new UnityEngine.Texture2D or loads an existing UnityEngine.Texture2D with the given path. More...
 
virtual string FixNodeName (string name, uint nodeId)
 Generates a unique node name, if the given name is empty. More...
 
virtual string FixName (string name, uint id)
 Generates a unique name, if the given name is empty. More...
 
virtual string FixName (string name)
 Generates a unique name using GUIDs, if the given name is empty. More...
 
void ReleaseImport ()
 Releases allocated resources. More...
 
- Protected Attributes inherited from TriLib.AssetLoaderBase
const string AssimpFilenameMagicString = "$$$___magic___$$$"
 Assimp uses this prefix when loading files from memory. More...
 
NodeData RootNodeData
 Main scene TriLib.NodeData. More...
 
MaterialData [] MaterialData
 Processed TriLib.MaterialData list. More...
 
MeshData [] MeshData
 Processed TriLib.MeshData list. More...
 
AnimationData [] AnimationData
 Processed TriLib.AnimationData list. More...
 
CameraData [] CameraData
 Processed TriLib.CameraData list. More...
 
AssimpMetadata [] Metadata
 Processed TriLib.AssimpMetadata list. More...
 
Dictionary< string, string > NodesPath
 Processed nodes path dictionary. More...
 
Dictionary< string, Material > LoadedMaterials
 Loaded UnityEngine.Material for a given name dictionary. More...
 
Dictionary< string, Texture2D > LoadedTextures
 Loaded UnityEngine.Texture2D for a given name dictionary. More...
 
Dictionary< SkinnedMeshRenderer, IList< string > > LoadedBoneNames
 Loaded bone names for a given UnityEngine.SkinnedMeshRenderer dictionary. More...
 
Dictionary< string, MeshDataMeshDataConnections
 UnityEngine.GameObject and MeshData relationship dictionary used to apply blend-shape animations. More...
 
Dictionary< string, EmbeddedTextureData > EmbeddedTextures
 Loaded EmbeddedTextureData for a given name dictionary. More...
 
uint NodeId
 Used to temporarily store nodes id. More...
 
bool HasBoneInfo
 Used to temporarily indicate if there are any bones assigned to loaded meshes. More...
 
bool HasBlendShapes
 Used to temporarily indicate if there are any blend shapes assigned to loaded meshes. More...
 
IntPtr Scene
 Pointer to Assimp loaded scene. More...
 
- Static Protected Attributes inherited from TriLib.AssetLoaderBase
static Material StandardBaseMaterial
 Base Diffuse UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularMaterial
 Base Specular UnityEngine.Material used to load materials. More...
 
static Material StandardBaseAlphaMaterial
 Base Diffuse Alpha UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularAlphaMaterial
 Base Specular Alpha UnityEngine.Material used to load materials. More...
 
static Material StandardBaseCutoutMaterial
 Base Diffuse Cutout UnityEngine.Material used to load materials. More...
 
static Material StandardSpecularCutoutMaterial
 Base Specular Cutout UnityEngine.Material used to load materials. More...
 
static Texture2D NotFoundTexture
 UnityEngine.Texture used to show when no texture is found. More...
 
- Properties inherited from TriLib.AssetLoaderBase
bool HasOnMeshCreated [get]
 Gets a value indicating whether this instance has on mesh created event. More...
 
bool HasOnMaterialCreated [get]
 Gets a value indicating whether this instance has on material created event. More...
 
bool HasOnTextureLoaded [get]
 Gets a value indicating whether this instance has on texture loaded event. More...
 
bool HasOnAnimationClipCreated [get]
 Gets a value indicating whether this instance has on animation clip created event. More...
 
bool HasOnObjectLoaded [get]
 Gets a value indicating whether this instance has on object loaded event. More...
 
bool HasOnMetadataProcessed [get]
 Gets a value indicating whether this instance has on metadata processed event. More...
 
bool HasOnBlendShapeKeyCreated [get]
 Gets a value indicating whether this instance has on blend-shape key created event. More...
 
- Events inherited from TriLib.AssetLoaderBase
EmbeddedTextureLoadCallback EmbeddedTextureLoad
 Use this field to assign the callback that will be triggered when a texture looks up for embedded data. More...
 
MeshCreatedHandle OnMeshCreated
 Use this field to assign the event that occurs when a mesh is loaded. More...
 
MaterialCreatedHandle OnMaterialCreated
 Use this field to assign the event that occurs when a material is created. More...
 
TextureLoadHandle OnTextureLoaded
 Use this field to assign the event that occurs when a texture is loaded. More...
 
AnimationClipCreatedHandle OnAnimationClipCreated
 Use this field to assign the event that occurs when an animation is created. More...
 
ObjectLoadedHandle OnObjectLoaded
 Use this field to assign the event that occurs when the asset is loaded. More...
 
MetadataProcessedHandle OnMetadataProcessed
 Use this field to assign the event that will occurs when each file metadata is processed. More...
 
BlendShapeKeyCreatedHandle OnBlendShapeKeyCreated
 Use this field to assign the event that occurs when a blend-shape key is created. More...
 

Detailed Description

Represents a synchronous asset loader.

Member Function Documentation

◆ LoadFromFile()

GameObject TriLib.AssetLoader.LoadFromFile ( string  filename,
AssetLoaderOptions  options = null,
GameObject  wrapperGameObject = null,
string  basePath = null,
AssimpInterop.ProgressCallback  progressCallback = null 
)

Loads a UnityEngine.GameObject from input filename with defined options.

Warning
To ensure your materials will be loaded, don´t remove the material files included in the package.
Parameters
filenameFilename used to load the UnityEngine.GameObject.
optionsAssetLoaderOptions used to load the object.
wrapperGameObjectUse this field to load the new UnityEngine.GameObject into referenced UnityEngine.GameObject.
basePathBase path from the loaded file.
progressCallbackCallback used to retrieve file loading percentage.
Returns
A new UnityEngine.GameObject.
protected void Awake() {
GameObject myGameObject;
try {
using (var assetLoader = new AssetLoader()) {
gameObject = assetLoader.LoadFromFile("mymodel.fbx");
}
} catch (Exception e) {
Debug.LogFormat("Unable to load mymodel.fbx. The loader returned: {0}", e);
}
}

◆ LoadFromFileWithTextures()

GameObject TriLib.AssetLoader.LoadFromFileWithTextures ( string  filename,
AssetLoaderOptions  options = null,
GameObject  wrapperGameObject = null,
string  basePath = null,
AssimpInterop.ProgressCallback  progressCallback = null 
)

Loads a UnityEngine.GameObject from file (Accept ZIP files).

Parameters
filenameFilename used to load the UnityEngine.GameObject.
optionsAssetLoaderOptions used to load the object.
wrapperGameObjectUse this field to load the new UnityEngine.GameObject into referenced UnityEngine.GameObject.
basePathBase path from the loaded file.
progressCallbackCallback used to retrieve file loading percentage.
Returns
true if model was loaded, otherwise false.

◆ LoadFromMemory()

GameObject TriLib.AssetLoader.LoadFromMemory ( byte []  fileBytes,
string  filename,
AssetLoaderOptions  options = null,
GameObject  wrapperGameObject = null,
string  basePath = null,
AssimpInterop.DataCallback  dataCallback = null,
AssimpInterop.ExistsCallback  existsCallback = null,
LoadTextureDataCallback  loadTextureDataCallback = null,
AssimpInterop.ProgressCallback  progressCallback = null 
)

Loads a UnityEngine.GameObject from input byte array with defined options.

Warning
To ensure your materials will be loaded, don´t remove material files included in the package.
Parameters
fileBytesData used to load the UnityEngine.GameObject.
filenameOriginal file name, if you know it. Otherwise, use the original file extension instead. (Eg: ".FBX")
optionsAssetLoaderOptions used to load the object.
wrapperGameObjectUse this field to load the new UnityEngine.GameObject into referenced UnityEngine.GameObject.
basePathBase path from the loaded file.
dataCallbackCustom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.
existsCallbackCustom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.
loadTextureDataCallbackPass this callback to load texture data from custom sources.
progressCallbackCallback used to retrieve file loading percentage.
Returns
A new UnityEngine.GameObject.
protected void Awake() {
GameObject myGameObject;
try {
using (var assetLoader = new AssetLoader()) {
//In case you don't have a valid filename, set this to the file extension
//to help TriLib assigning a file loader to this file
//example value: ".FBX"
var filename = "c:/models/mymodel.fbx";
var fileData = File.ReadAllBytes(filename);
gameObject = assetLoader.LoadFromMemory(fleData, filename);
}
} catch (Exception e) {
Debug.LogFormat("Unable to load mymodel.fbx. The loader returned: {0}", e);
}
}

◆ LoadFromMemoryWithTextures()

GameObject TriLib.AssetLoader.LoadFromMemoryWithTextures ( byte []  fileData,
string  assetExtension,
AssetLoaderOptions  options = null,
GameObject  wrapperGameObject = null,
string  basePath = null,
AssimpInterop.DataCallback  dataCallback = null,
AssimpInterop.ExistsCallback  existsCallback = null,
AssimpInterop.ProgressCallback  progressCallback = null 
)

Loads a UnityEngine.GameObject from input byte array (Accept ZIP files).

Parameters
fileDataFile data.
assetExtensionAsset extension.
optionsAssetLoaderOptions used to load the object.
wrapperGameObjectUse this field to load the new UnityEngine.GameObject into referenced UnityEngine.GameObject.
basePathBase path from the loaded file.
dataCallbackCustom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.
existsCallbackCustom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.
progressCallbackCallback used to retrieve file loading percentage.
Returns
true if model was loaded, otherwise false.

The documentation for this class was generated from the following file: