TriLib
Search Results for

    Show / Hide Table of Contents

    Class TextureLoaders

    Provides methods for loading and processing textures (such as reading texture data, creating UnityEngine.Texture2D instances, and applying post-processing operations).

    Inheritance
    object
    TextureLoaders
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: TriLibCore.Textures
    Assembly: TriLibCore.dll
    Syntax
    public static class TextureLoaders

    Methods

    ApplyTexture(TextureLoadingContext, bool)

    Applies (uploads) the UnityEngine.Texture2D data to the GPU, optionally treating the texture as procedural if requested. See ApplyTexture2D(TextureLoadingContext, bool) for details.

    Declaration
    public static void ApplyTexture(TextureLoadingContext textureLoadingContext, bool procedural)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context containing the texture to apply.

    bool procedural

    true to treat the texture as procedural; false otherwise.

    CreateTexture(TextureLoadingContext)

    Creates a texture structure (e.g. UnityEngine.Texture2D) without fully loading pixel data, based on basic information (width, height, etc.) found via StbImageSharp.ImageInfo.

    Declaration
    public static void CreateTexture(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context that will contain the created texture.

    CreateTextureInternal(TextureLoadingContext)

    Creates a UnityEngine.Texture2D in textureLoadingContext, respecting the MaxTexturesResolution setting. Called internally once width/height are known.

    Declaration
    public static void CreateTextureInternal(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context to update with the newly created texture.

    FixNPOTTexture(TextureLoadingContext)

    Fixes a non-power-of-two (NPOT) texture by rescaling it to the nearest power-of-two resolution if needed.

    Declaration
    public static void FixNPOTTexture(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context containing the texture to fix.

    FixNormalMap(TextureLoadingContext)

    If the texture in textureLoadingContext is recognized as a normal map, adjusts its channels to properly match Unity’s normal map expectations.

    Declaration
    public static void FixNormalMap(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context containing the texture to fix.

    LoadTexture(TextureLoadingContext)

    Loads a Unity texture from the data provided in the textureLoadingContext. This method attempts to read raw or embedded texture data, then either uses Unity’s native LoadImage or StbImageSharp to decode the image into a UnityEngine.Texture2D.

    Declaration
    public static bool LoadTexture(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The TextureLoadingContext containing streams, raw data, and options for texture creation.

    Returns
    Type Description
    bool

    true if the texture was successfully loaded; otherwise, false.

    PostProcessTexture(TextureLoadingContext)

    Applies any post-processing to the texture as dictated by the IMaterial in MaterialMapperContext, then marks the texture as processed.

    Declaration
    public static bool PostProcessTexture(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context containing the texture to post-process.

    Returns
    Type Description
    bool

    A value indicating whether the material actually performed any post-processing.

    ResolveFilename(ITexture, AssetLoaderContext)

    Attempts to resolve the Filename by searching in assetLoaderContext. This may update ResolvedFilename if a matching file is found.

    Declaration
    public static void ResolveFilename(this ITexture texture, AssetLoaderContext assetLoaderContext)
    Parameters
    Type Name Description
    ITexture texture

    The texture to resolve.

    AssetLoaderContext assetLoaderContext

    The AssetLoaderContext that provides the base path and other loading options.

    ScanForAlphaPixels(TextureLoadingContext)

    Scans the texture’s pixel data for alpha values to detect if the texture contains any non-opaque pixels. Updates HasAlpha accordingly.

    Declaration
    public static void ScanForAlphaPixels(TextureLoadingContext textureLoadingContext)
    Parameters
    Type Name Description
    TextureLoadingContext textureLoadingContext

    The context with texture data and format details.

    WriteToFile(Stream, string, int, FileMode, FileAccess, FileShare)

    Writes the contents of stream into a file at destinationFile using the specified buffer size and file sharing mode.

    Declaration
    public static void WriteToFile(Stream stream, string destinationFile, int bufferSize = 4096, FileMode mode = FileMode.OpenOrCreate, FileAccess access = FileAccess.ReadWrite, FileShare share = FileShare.ReadWrite)
    Parameters
    Type Name Description
    Stream stream

    The source stream to read from.

    string destinationFile

    The file path to write to.

    int bufferSize

    The size (in bytes) of the buffer used while copying the stream.

    FileMode mode

    A FileMode specifying how the file is opened or created. Defaults to OpenOrCreate.

    FileAccess access

    A FileAccess specifying the level of access permitted. Defaults to ReadWrite.

    FileShare share

    A FileShare specifying the type of access other processes have to the file. Defaults to ReadWrite.

    In this article
    Back to top Generated by DocFX