TriLib
Search Results for

    Show / Hide Table of Contents

    Class SimpleCustomAssetLoader

    Provides static methods for loading 3D models from byte arrays or Stream objects. This class integrates custom data and texture mappers via user-supplied callbacks, enabling flexible loading scenarios such as in-memory data, custom file paths, or network streams.

    Inheritance
    object
    SimpleCustomAssetLoader
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: TriLibCore.Samples
    Assembly: Assembly-CSharp.dll
    Syntax
    public class SimpleCustomAssetLoader

    Methods

    LoadModelFromByteData(byte[], string, Action<IContextualizedError>, Action<AssetLoaderContext, float>, Action<AssetLoaderContext>, Func<string, Stream>, Func<string, string>, Func<ITexture, Stream>, string, GameObject, AssetLoaderOptions, object)

    Loads a model from an in-memory byte array, using callbacks to handle events and external data.

    Declaration
    public static AssetLoaderContext LoadModelFromByteData(byte[] data, string modelExtension, Action<IContextualizedError> onError, Action<AssetLoaderContext, float> onProgress, Action<AssetLoaderContext> onModelFullyLoad, Func<string, Stream> customDataReceivingCallback, Func<string, string> customFilenameReceivingCallback, Func<ITexture, Stream> customTextureReceivingCallback, string modelFilename = null, GameObject wrapperGameObject = null, AssetLoaderOptions assetLoaderOptions = null, object customData = null)
    Parameters
    Type Name Description
    byte[] data

    The raw byte array containing the model data.

    string modelExtension

    The model file extension (e.g., ".fbx", ".obj"). If omitted, you can provide a modelFilename to infer the extension.

    Action<IContextualizedError> onError

    An optional callback invoked if an error occurs during loading.

    Action<AssetLoaderContext, float> onProgress

    A callback invoked to report loading progress, where the float parameter goes from 0.0 to 1.0.

    Action<AssetLoaderContext> onModelFullyLoad

    A callback invoked once the model is fully loaded (including textures and materials).

    Func<string, Stream> customDataReceivingCallback

    A required callback for obtaining external file data streams when additional files are referenced.

    Func<string, string> customFilenameReceivingCallback

    An optional callback to resolve or modify the final filename from the original reference.

    Func<ITexture, Stream> customTextureReceivingCallback

    A required callback for obtaining texture data streams.

    string modelFilename

    An optional filename to associate with the model. If provided, TriLib may use this to infer the file extension.

    GameObject wrapperGameObject

    An optional UnityEngine.GameObject to serve as a parent for the loaded model’s root object.

    AssetLoaderOptions assetLoaderOptions

    An optional set of loading options for finer control over the model load process.

    object customData

    Any custom user data that should be passed through TriLib’s loading pipeline and accessible in callbacks.

    Returns
    Type Description
    AssetLoaderContext

    An AssetLoaderContext containing references to the loaded root UnityEngine.GameObject and other metadata.

    Exceptions
    Type Condition
    Exception

    Thrown if data is null or empty.

    LoadModelFromStream(Stream, string, Action<IContextualizedError>, Action<AssetLoaderContext, float>, Action<AssetLoaderContext>, Func<string, Stream>, Func<string, string>, Func<ITexture, Stream>, string, GameObject, AssetLoaderOptions, object)

    Loads a model from a Stream, using callbacks to handle external data and textures.

    Declaration
    public static AssetLoaderContext LoadModelFromStream(Stream stream, string modelExtension, Action<IContextualizedError> onError, Action<AssetLoaderContext, float> onProgress, Action<AssetLoaderContext> onModelFullyLoad, Func<string, Stream> customDataReceivingCallback, Func<string, string> customFilenameReceivingCallback, Func<ITexture, Stream> customTextureReceivingCallback, string modelFilename = null, GameObject wrapperGameObject = null, AssetLoaderOptions assetLoaderOptions = null, object customData = null)
    Parameters
    Type Name Description
    Stream stream

    The Stream containing the model data.

    string modelExtension

    The model file extension (e.g., ".fbx", ".obj"). This is used by TriLib to determine import logic.

    Action<IContextualizedError> onError

    An optional callback invoked if an error occurs during loading.

    Action<AssetLoaderContext, float> onProgress

    A callback to report loading progress, from 0.0 (start) to 1.0 (fully loaded).

    Action<AssetLoaderContext> onModelFullyLoad

    A callback invoked once the model is fully loaded (including meshes, materials, and textures).

    Func<string, Stream> customDataReceivingCallback

    A required callback for obtaining streams to any external file data the model references.

    Func<string, string> customFilenameReceivingCallback

    An optional callback to modify or resolve filenames before loading.

    Func<ITexture, Stream> customTextureReceivingCallback

    A required callback for obtaining texture data streams.

    string modelFilename

    An optional filename to represent the model. If an extension is not provided in modelExtension, it will be derived from this parameter.

    GameObject wrapperGameObject

    An optional UnityEngine.GameObject that will become the parent of the loaded model’s root UnityEngine.GameObject.

    AssetLoaderOptions assetLoaderOptions

    Optional loading options to customize import settings, scaling, etc.

    object customData

    Any additional user data to be passed through the loading pipeline and accessible within callbacks.

    Returns
    Type Description
    AssetLoaderContext

    An AssetLoaderContext containing the loaded model’s references and metadata.

    Remarks

    This method is useful if you have already prepared a Stream, such as from a custom data source, a file, or network operation. You can attach event callbacks to monitor progress, receive errors, and handle external dependencies or textures.

    Exceptions
    Type Condition
    Exception

    Thrown if stream is null or if the model extension cannot be resolved.

    Extension Methods

    IObjectExtensions.TryToDispose<T>(object)
    In this article
    Back to top Generated by DocFX