docs.unity3d.com
    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
    Namespace: UnityEngine.Perception.GroundTruth
    Syntax
    public static class InstanceIdToColorMapping : object

    Fields

    invalidColor

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

    Declaration
    public static readonly Color32 invalidColor
    Field Value
    Type Description
    Color32

    maxId

    The max ID supported by this class.

    Declaration
    public const uint maxId = null
    Field Value
    Type Description
    UInt32

    Methods

    GetColorFromInstanceId(UInt32)

    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
    UInt32 id

    The ID of interest.

    Returns
    Type Description
    Color32

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

    GetColorFromPackedColor(UInt32)

    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
    UInt32 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
    UInt32

    The ID for the passed in color.

    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
    UInt32

    The packed unsigned int 32 of the color.

    TryGetColorFromInstanceId(UInt32, 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
    UInt32 id

    The ID of interest.

    Color32 color

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

    Returns
    Type Description
    Boolean

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

    TryGetInstanceIdFromColor(Color32, out UInt32)

    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.

    UInt32 id

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

    Returns
    Type Description
    Boolean

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

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023