docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InstanceIdToColorMapping

    Static class to procedurally generate a unique color for an instance ID. This algorithm is deterministic, and will always return the same color for a ID, and the same ID for a color. ID 0 is reserved to be an invalid ID and is mapped to color black (0,0,0,255). Invalid IDs always map to black, and black always maps to ID 0. In order to try to create visually contrasting colors for IDs, there are a subset of IDs reserved (1-65) to be generated by applying the golden ration to find the next color in the HSL spectrum. All of these colors, and only theses colors, will be in the alpha channel 255. After the first 65 IDs, the color will be determined by iterating through all available RGB values in the alpha channels from 264 - 1. Alpha channel 0 is marked as invalid. This service will support over 4 billion unique IDs => colors [(256^4) - (256*2) + 64]

    Inheritance
    object
    InstanceIdToColorMapping
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.Perception.GroundTruth.Utilities
    Assembly: Unity.Perception.Runtime.dll
    Syntax
    [MovedFrom("UnityEngine.Perception.GroundTruth")]
    public static class InstanceIdToColorMapping

    Fields

    invalidColor

    The color returned when an instanceId is not mapped to any color, and for clearing ground truth material properties on a MaterialPropertyBlock.

    Declaration
    public static readonly Color32 invalidColor
    Field Value
    Type Description
    Color32

    maxId

    The max ID supported by this class.

    Declaration
    public const uint maxId = 4261413887
    Field Value
    Type Description
    uint

    Methods

    GetColorFromInstanceId(uint)

    Retrieve the color that is mapped to the passed in ID. If the ID is 0 or 255 the returned color will be black.

    Declaration
    public static Color32 GetColorFromInstanceId(uint id)
    Parameters
    Type Name Description
    uint id

    The ID of interest.

    Returns
    Type Description
    Color32

    The color associated with the passed in ID, or black if no associated color exists.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if the passed in ID is greater than the largest supported ID maxId

    GetColorFromPackedColor(uint)

    Converts a packed color (or unsigned 32bit representation of a color) into an RGBA color.

    Declaration
    public static Color32 GetColorFromPackedColor(uint color)
    Parameters
    Type Name Description
    uint color

    The packed color

    Returns
    Type Description
    Color32

    The RGBA color

    GetInstanceIdFromColor(Color32)

    Retrieve the ID associated with the passed in color. If the passed in color is black this service will return 0.

    Declaration
    public static uint GetInstanceIdFromColor(Color32 color)
    Parameters
    Type Name Description
    Color32 color

    The color to map to an ID.

    Returns
    Type Description
    uint

    The ID for the passed in color.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if the passed in color is mapped to an ID that is greater than the largest supported ID

    InvalidOperationException

    Thrown if the passed in color cannot be mapped to an ID in the alpha 255 rangemaxId

    GetPackedColorFromColor(Color32)

    Packs a color32 (RGBA - 1 byte per channel) into a 32bit unsigned integer.

    Declaration
    public static uint GetPackedColorFromColor(Color32 color)
    Parameters
    Type Name Description
    Color32 color

    The RGBA color.

    Returns
    Type Description
    uint

    The packed unsigned int 32 of the color.

    TryGetColorFromInstanceId(uint, out Color32)

    Retrieve the color that is mapped to the passed in ID. If the ID is 0 or 255 false will be returned, and color will be set to black.

    Declaration
    public static bool TryGetColorFromInstanceId(uint id, out Color32 color)
    Parameters
    Type Name Description
    uint id

    The ID of interest.

    Color32 color

    Will be set to the color associated with the passed in ID.

    Returns
    Type Description
    bool

    Returns true if the ID was mapped to a non-black color, otherwise returns false

    TryGetInstanceIdFromColor(Color32, out uint)

    Retrieve the ID associated with the passed in color. If the passed in color is black or cannot be mapped to an ID this service will return false, and the out id will be set to 0.

    Declaration
    public static bool TryGetInstanceIdFromColor(Color32 color, out uint id)
    Parameters
    Type Name Description
    Color32 color

    The color to map to an ID.

    uint id

    This value will be updated with the ID for the passed in color.

    Returns
    Type Description
    bool

    This service will return true if an ID is properly mapped to a color, otherwise it will return false.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)